| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.security.net.config; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
|
| 21 |
import java.util.Arrays; |
| 22 |
|
| 23 |
|
| 24 |
public final class Pin { |
| 25 |
public final String digestAlgorithm; |
| 26 |
public final byte[] digest; |
| 27 |
|
| 28 |
private final int mHashCode; |
| 29 |
|
| 30 |
public Pin(String digestAlgorithm, byte[] digest) { |
| 31 |
this.digestAlgorithm = digestAlgorithm; |
| 32 |
this.digest = digest; |
| 33 |
mHashCode = Arrays.hashCode(digest) ^ digestAlgorithm.hashCode(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public static boolean isSupportedDigestAlgorithm(String algorithm) { |
| 40 |
|
| 41 |
|
| 42 |
return "SHA-256".equalsIgnoreCase(algorithm); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public static int getDigestLength(String algorithm) { |
| 49 |
if ("SHA-256".equalsIgnoreCase(algorithm)) { |
| 50 |
return 32; |
| 51 |
} |
| 52 |
throw new IllegalArgumentException("Unsupported digest algorithm: " + algorithm); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public int hashCode() { |
| 57 |
return mHashCode; |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public boolean equals(@Nullable Object obj) { |
| 62 |
if (this == obj) { |
| 63 |
return true; |
| 64 |
} |
| 65 |
if (!(obj instanceof Pin)) { |
| 66 |
return false; |
| 67 |
} |
| 68 |
Pin other = (Pin) obj; |
| 69 |
if (other.hashCode() != mHashCode) { |
| 70 |
return false; |
| 71 |
} |
| 72 |
if (!Arrays.equals(digest, other.digest)) { |
| 73 |
return false; |
| 74 |
} |
| 75 |
if (!digestAlgorithm.equals(other.digestAlgorithm)) { |
| 76 |
return false; |
| 77 |
} |
| 78 |
return true; |
| 79 |
} |
| 80 |
} |