Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e36fe6bf authored by Janis Danisevskis's avatar Janis Danisevskis
Browse files

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
parent 6297dd27
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.system.keystore2.KeyDescriptor;
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 @@ 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;
    }
@@ -83,7 +83,7 @@ public abstract class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implem
         */
        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);
    }
}