Set a default value for period and digits for new entries

This is also in preparation for #24, but I haven't fully figured out how to do
that nicely yet, so that'll come later.
This commit is contained in:
Alexander Bakker 2019-09-04 21:42:01 +02:00
parent 85bdecc573
commit e019fb6db2
3 changed files with 71 additions and 58 deletions

View file

@ -5,6 +5,7 @@ import com.beemdevelopment.aegis.encoding.Base64Exception;
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
import com.beemdevelopment.aegis.otp.OtpInfo;
import com.beemdevelopment.aegis.otp.OtpInfoException;
import com.beemdevelopment.aegis.otp.TotpInfo;
import com.beemdevelopment.aegis.util.UUIDMap;
import org.json.JSONException;
@ -133,11 +134,34 @@ public class DatabaseEntry extends UUIDMap.Value {
}
DatabaseEntry entry = (DatabaseEntry) o;
return super.equals(entry)
&& getName().equals(entry.getName())
return super.equals(entry) && equivalates(entry);
}
/**
* Reports whether this entry is equivalent to the given entry. The UUIDs of these
* entries are ignored during the comparison, so they are not necessarily the same
* instance.
*/
public boolean equivalates(DatabaseEntry entry) {
return getName().equals(entry.getName())
&& getIssuer().equals(entry.getIssuer())
&& Objects.equals(getGroup(), entry.getGroup())
&& getInfo().equals(entry.getInfo())
&& Arrays.equals(getIcon(), entry.getIcon());
}
/**
* Reports whether this entry has its values set to the defaults.
*/
public boolean isDefault() {
return equivalates(getDefault());
}
public static DatabaseEntry getDefault() {
try {
return new DatabaseEntry(new TotpInfo(null));
} catch (OtpInfoException e) {
throw new RuntimeException(e);
}
}
}