summaryrefslogtreecommitdiff
path: root/keystore/java
diff options
context:
space:
mode:
author Janis Danisevskis <jdanis@google.com> 2021-08-10 17:47:43 -0700
committer Janis Danisevskis <jdanis@google.com> 2021-08-12 12:29:02 -0700
commit7bdc12d5f36ed0602811b56019e449bf775c868d (patch)
treeee57476c51048c0830eab0d50d462782573c406a /keystore/java
parent99e5c70ff088cb92833dfbeb98ffb905f71b7c3b (diff)
Keystore 2.0 SPI: Fix contract between equals and hashCode
This fixes the contract between equals and hashCode in AndroidKeystoreKey and AndroidKeystorePublicKey. Bug: 196118021 Test: N/A Change-Id: I3f7e6d72d53c7051c13daeb5aa6ce1abf4eb0cc5
Diffstat (limited to 'keystore/java')
-rw-r--r--keystore/java/android/security/keystore2/AndroidKeyStoreKey.java10
-rw-r--r--keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java14
2 files changed, 12 insertions, 12 deletions
diff --git a/keystore/java/android/security/keystore2/AndroidKeyStoreKey.java b/keystore/java/android/security/keystore2/AndroidKeyStoreKey.java
index 5619585d9c3c..b24a22dbc0ec 100644
--- a/keystore/java/android/security/keystore2/AndroidKeyStoreKey.java
+++ b/keystore/java/android/security/keystore2/AndroidKeyStoreKey.java
@@ -102,11 +102,9 @@ public class AndroidKeyStoreKey implements Key {
final int prime = 31;
int result = 1;
- result = prime * result + ((mDescriptor == null) ? 0 : mDescriptor.hashCode());
+ result = prime * result + getClass().hashCode();
result = prime * result + (int) (mKeyId >>> 32);
result = prime * result + (int) (mKeyId & 0xffffffff);
- result = prime * result + ((mAuthorizations == null) ? 0 : mAuthorizations.hashCode());
- result = prime * result + ((mAlgorithm == null) ? 0 : mAlgorithm.hashCode());
return result;
}
@@ -122,10 +120,6 @@ public class AndroidKeyStoreKey implements Key {
return false;
}
AndroidKeyStoreKey other = (AndroidKeyStoreKey) obj;
- if (mKeyId != other.mKeyId) {
- return false;
- }
-
- return true;
+ return mKeyId == other.mKeyId;
}
}
diff --git a/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java b/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java
index db3e567cb6b4..4842984e8c6a 100644
--- a/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java
+++ b/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java
@@ -23,6 +23,7 @@ import android.system.keystore2.KeyDescriptor;
import android.system.keystore2.KeyMetadata;
import java.security.PublicKey;
+import java.util.Objects;
/**
* {@link PublicKey} backed by Android Keystore.
@@ -75,9 +76,14 @@ public abstract class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implem
if (!super.equals(obj)) {
return false;
}
- if (getClass() != obj.getClass()) {
- return false;
- }
- return true;
+
+ /*
+ * getClass().equals(ojb.getClass()) is implied by the call to super.equals() above. This
+ * means we can cast obj to AndroidKeyStorePublicKey here.
+ */
+ final AndroidKeyStorePublicKey other = (AndroidKeyStorePublicKey) obj;
+
+ return Objects.equals(mCertificate, other.mCertificate) && Objects.equals(mCertificateChain,
+ other.mCertificateChain);
}
}