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: See next CL. Merged-In: I3f7e6d72d53c7051c13daeb5aa6ce1abf4eb0cc5 Change-Id: I3f7e6d72d53c7051c13daeb5aa6ce1abf4eb0cc5
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.system.keystore2.KeyDescriptor;
|
||||
import android.system.keystore2.KeyMetadata;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* {@link PublicKey} backed by Android Keystore.
|
||||
@@ -61,8 +62,8 @@ public abstract class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implem
|
||||
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;
|
||||
}
|
||||
@@ -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 Arrays.equals(mCertificate, other.mCertificate) && Arrays.equals(mCertificateChain,
|
||||
other.mCertificateChain);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user