1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.security.keystore; 18 19import java.security.PublicKey; 20import java.util.Arrays; 21 22/** 23 * {@link PublicKey} backed by Android Keystore. 24 * 25 * @hide 26 */ 27public class AndroidKeyStorePublicKey extends AndroidKeyStoreKey implements PublicKey { 28 29 private final byte[] mEncoded; 30 31 public AndroidKeyStorePublicKey(String alias, int uid, String algorithm, byte[] x509EncodedForm) { 32 super(alias, uid, algorithm); 33 mEncoded = ArrayUtils.cloneIfNotEmpty(x509EncodedForm); 34 } 35 36 @Override 37 public String getFormat() { 38 return "X.509"; 39 } 40 41 @Override 42 public byte[] getEncoded() { 43 return ArrayUtils.cloneIfNotEmpty(mEncoded); 44 } 45 46 @Override 47 public int hashCode() { 48 final int prime = 31; 49 int result = super.hashCode(); 50 result = prime * result + Arrays.hashCode(mEncoded); 51 return result; 52 } 53 54 @Override 55 public boolean equals(Object obj) { 56 if (this == obj) { 57 return true; 58 } 59 if (!super.equals(obj)) { 60 return false; 61 } 62 if (getClass() != obj.getClass()) { 63 return false; 64 } 65 AndroidKeyStorePublicKey other = (AndroidKeyStorePublicKey) obj; 66 if (!Arrays.equals(mEncoded, other.mEncoded)) { 67 return false; 68 } 69 return true; 70 } 71} 72