Fix hashCode function for Entry

This commit is contained in:
Jakob Nixdorf 2017-07-14 20:01:26 +02:00
parent 3543cc9685
commit ea2b18bde9
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC

View file

@ -44,10 +44,10 @@ public class Entry {
private static final String JSON_PERIOD = "period"; private static final String JSON_PERIOD = "period";
private static final String JSON_TYPE = "type"; private static final String JSON_TYPE = "type";
private OTPType type; private OTPType type = OTPType.TOTP;
private byte[] secret; private byte[] secret;
private String label; private String label;
private int period; private int period = TOTPHelper.TOTP_DEFAULT_PERIOD;
private String currentOTP; private String currentOTP;
private long last_update = 0; private long last_update = 0;
@ -190,8 +190,12 @@ public class Entry {
@Override @Override
public int hashCode() { public int hashCode() {
int result = secret != null ? Arrays.hashCode(secret) : 0; int hash = 1;
result = 31 * result + (label != null ? label.hashCode() : 0); hash = hash + (secret == null ? 0 : Arrays.hashCode(secret));
return result; hash = hash + 13 * (label == null ? 0 : label.hashCode());
hash = hash + 17 * type.hashCode();
hash = hash + 31 * period;
return hash;
} }
} }