Keystore 2.0 SPI: Fix contract between equals and hashCode 2
This fixes the contract between equals and hashCode in
AndroidKeystorePublicKey. The previous fix made only a reference
comparisson between certificate blobs. In this patch java.util.Arrays is
used to compare and compute the hash of the array.
Bug: 196118021
Test: See following CL.
Change-Id: I2b8b7e740fb377de39fd21f763e15cb00024b2fc
diff --git a/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java b/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java
index 4842984..0b3be32 100644
--- a/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java
+++ b/keystore/java/android/security/keystore2/AndroidKeyStorePublicKey.java
@@ -23,7 +23,7 @@
import android.system.keystore2.KeyMetadata;
import java.security.PublicKey;
-import java.util.Objects;
+import java.util.Arrays;
/**
* {@link PublicKey} backed by Android Keystore.
@@ -62,8 +62,8 @@
int result = 1;
result = prime * result + super.hashCode();
- result = prime * result + ((mCertificate == null) ? 0 : mCertificate.hashCode());
- result = prime * result + ((mCertificateChain == null) ? 0 : mCertificateChain.hashCode());
+ result = prime * result + Arrays.hashCode(mCertificate);
+ result = prime * result + Arrays.hashCode(mCertificateChain);
return result;
}
@@ -83,7 +83,7 @@
*/
final AndroidKeyStorePublicKey other = (AndroidKeyStorePublicKey) obj;
- return Objects.equals(mCertificate, other.mCertificate) && Objects.equals(mCertificateChain,
+ return Arrays.equals(mCertificate, other.mCertificate) && Arrays.equals(mCertificateChain,
other.mCertificateChain);
}
}