mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Support an arbitrary number of digits
This commit is contained in:
parent
4cf1a5efe4
commit
066a7447c0
4 changed files with 13 additions and 24 deletions
|
@ -78,7 +78,8 @@ public abstract class OtpInfo implements Serializable {
|
|||
}
|
||||
|
||||
public static boolean isDigitsValid(int digits) {
|
||||
return digits == 6 || digits == 8;
|
||||
// allow a max of 10 digits, as truncation will only extract 31 bits
|
||||
return digits > 0 && digits <= 10;
|
||||
}
|
||||
|
||||
public void setDigits(int digits) throws OtpInfoException {
|
||||
|
|
|
@ -74,6 +74,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
private EditText _textIssuer;
|
||||
private EditText _textPeriod;
|
||||
private EditText _textCounter;
|
||||
private EditText _textDigits;
|
||||
private EditText _textSecret;
|
||||
|
||||
private TableRow _rowPeriod;
|
||||
|
@ -81,7 +82,6 @@ public class EditEntryActivity extends AegisActivity {
|
|||
|
||||
private Spinner _spinnerType;
|
||||
private Spinner _spinnerAlgo;
|
||||
private Spinner _spinnerDigits;
|
||||
private Spinner _spinnerGroup;
|
||||
private List<String> _spinnerGroupList = new ArrayList<>();
|
||||
|
||||
|
@ -116,6 +116,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
_textName = findViewById(R.id.text_name);
|
||||
_textIssuer = findViewById(R.id.text_issuer);
|
||||
_textPeriod = findViewById(R.id.text_period);
|
||||
_textDigits = findViewById(R.id.text_digits);
|
||||
_rowPeriod = findViewById(R.id.row_period);
|
||||
_textCounter = findViewById(R.id.text_counter);
|
||||
_rowCounter = findViewById(R.id.row_counter);
|
||||
|
@ -124,8 +125,6 @@ public class EditEntryActivity extends AegisActivity {
|
|||
SpinnerHelper.fillSpinner(this, _spinnerType, R.array.otp_types_array);
|
||||
_spinnerAlgo = findViewById(R.id.spinner_algo);
|
||||
SpinnerHelper.fillSpinner(this, _spinnerAlgo, R.array.otp_algo_array);
|
||||
_spinnerDigits = findViewById(R.id.spinner_digits);
|
||||
SpinnerHelper.fillSpinner(this, _spinnerDigits, R.array.otp_digits_array);
|
||||
_spinnerGroup = findViewById(R.id.spinner_group);
|
||||
updateGroupSpinnerList();
|
||||
SpinnerHelper.fillSpinner(this, _spinnerGroup, _spinnerGroupList);
|
||||
|
@ -158,6 +157,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
} else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
_textDigits.setText(Integer.toString(info.getDigits()));
|
||||
|
||||
byte[] secretBytes = _origEntry.getInfo().getSecret();
|
||||
if (secretBytes != null) {
|
||||
|
@ -171,9 +171,6 @@ public class EditEntryActivity extends AegisActivity {
|
|||
String algo = _origEntry.getInfo().getAlgorithm(false);
|
||||
_spinnerAlgo.setSelection(getStringResourceIndex(R.array.otp_algo_array, algo), false);
|
||||
|
||||
String digits = Integer.toString(_origEntry.getInfo().getDigits());
|
||||
_spinnerDigits.setSelection(getStringResourceIndex(R.array.otp_digits_array, digits), false);
|
||||
|
||||
String group = _origEntry.getGroup();
|
||||
if (group != null) {
|
||||
int pos = _groups.contains(group) ? _groups.headSet(group).size() : -1;
|
||||
|
@ -439,7 +436,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
|
||||
int digits;
|
||||
try {
|
||||
digits = Integer.parseInt(_spinnerDigits.getSelectedItem().toString());
|
||||
digits = Integer.parseInt(_textDigits.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParseException("Digits is not an integer.");
|
||||
}
|
||||
|
|
|
@ -171,9 +171,8 @@
|
|||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/spinner_type"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="4"
|
||||
android:layout_marginLeft="-6dp"
|
||||
android:paddingRight="6dp"
|
||||
android:gravity="left"
|
||||
android:layout_gravity="left"
|
||||
|
@ -182,23 +181,19 @@
|
|||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/spinner_algo"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="4"
|
||||
android:layout_marginLeft="-6dp"
|
||||
android:paddingRight="6dp"
|
||||
android:textAlignment="center"
|
||||
android:backgroundTint="#949494"
|
||||
style="@style/Base.Widget.AppCompat.Spinner.Underlined"/>
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/spinner_digits"
|
||||
<EditText
|
||||
android:id="@+id/text_digits"
|
||||
android:hint="@string/digits"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="-6dp"
|
||||
android:paddingRight="6dp"
|
||||
android:layout_weight="3"
|
||||
android:textAlignment="center"
|
||||
android:backgroundTint="#949494"
|
||||
style="@style/Base.Widget.AppCompat.Spinner.Underlined"/>
|
||||
android:backgroundTint="#949494"/>
|
||||
</LinearLayout>
|
||||
|
||||
</TableRow>
|
||||
|
|
|
@ -74,17 +74,13 @@
|
|||
<item>SHA512</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="otp_digits_array">
|
||||
<item>6</item>
|
||||
<item>8</item>
|
||||
</string-array>
|
||||
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="unlock">Unlock</string>
|
||||
<string name="advanced">Advanced</string>
|
||||
<string name="seconds">seconds</string>
|
||||
<string name="counter">Counter</string>
|
||||
<string name="digits">Digits</string>
|
||||
<string name="secret">Secret</string>
|
||||
<string name="scan">Scan QR code</string>
|
||||
<string name="enter_manually">Enter manually</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue