diff options
author | Kenny Root <kroot@google.com> | 2013-05-07 16:54:21 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-05-07 16:54:21 +0000 |
commit | 30abb655066afb5eeaebb874efd7cb10ae4013ff (patch) | |
tree | 23f65879a9eba115b57d98190126dc91423f34c2 | |
parent | dafcbf80f82fbd9ecb48bd7f04b894a28afe6104 (diff) | |
parent | bd788522b36f03dc12750c69fd8b3733ef3801bd (diff) | |
download | libcore-30abb655066afb5eeaebb874efd7cb10ae4013ff.zip libcore-30abb655066afb5eeaebb874efd7cb10ae4013ff.tar.gz libcore-30abb655066afb5eeaebb874efd7cb10ae4013ff.tar.bz2 |
Merge "NativeCrypto: make our own X.509 key class"
-rw-r--r-- | crypto/src/main/java/org/conscrypt/OpenSSLX509Certificate.java | 3 | ||||
-rw-r--r-- | crypto/src/main/java/org/conscrypt/X509PublicKey.java | 86 |
2 files changed, 87 insertions, 2 deletions
diff --git a/crypto/src/main/java/org/conscrypt/OpenSSLX509Certificate.java b/crypto/src/main/java/org/conscrypt/OpenSSLX509Certificate.java index bd4e536..0a0615f 100644 --- a/crypto/src/main/java/org/conscrypt/OpenSSLX509Certificate.java +++ b/crypto/src/main/java/org/conscrypt/OpenSSLX509Certificate.java @@ -47,7 +47,6 @@ import java.util.Set; import java.util.TimeZone; import javax.security.auth.x500.X500Principal; import org.apache.harmony.security.utils.AlgNameMapper; -import org.apache.harmony.security.x509.X509PublicKey; import org.conscrypt.OpenSSLX509CertificateFactory.ParsingException; public class OpenSSLX509Certificate extends X509Certificate { @@ -410,7 +409,7 @@ public class OpenSSLX509Certificate extends X509Certificate { * We couldn't find anything else, so just return a nearly-unusable * X.509-encoded key. */ - return new X509PublicKey(oid, encoded, null); + return new X509PublicKey(oid, encoded); } @Override diff --git a/crypto/src/main/java/org/conscrypt/X509PublicKey.java b/crypto/src/main/java/org/conscrypt/X509PublicKey.java new file mode 100644 index 0000000..8d09fc2 --- /dev/null +++ b/crypto/src/main/java/org/conscrypt/X509PublicKey.java @@ -0,0 +1,86 @@ +/* + * Copyright 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.conscrypt; + +import java.security.PublicKey; +import java.util.Arrays; + +/** + * A simple but useless key class that holds X.509 public key information when + * the appropriate KeyFactory for the key algorithm is not available. + */ +public class X509PublicKey implements PublicKey { + private static final long serialVersionUID = -8610156854731664298L; + + private final String algorithm; + + private final byte[] encoded; + + public X509PublicKey(String algorithm, byte[] encoded) { + this.algorithm = algorithm; + this.encoded = encoded; + } + + @Override + public String getAlgorithm() { + return algorithm; + } + + @Override + public String getFormat() { + return "X.509"; + } + + @Override + public byte[] getEncoded() { + return encoded; + } + + @Override + public String toString() { + return "X509PublicKey [algorithm=" + algorithm + ", encoded=" + Arrays.toString(encoded) + + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((algorithm == null) ? 0 : algorithm.hashCode()); + result = prime * result + Arrays.hashCode(encoded); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + X509PublicKey other = (X509PublicKey) obj; + if (algorithm == null) { + if (other.algorithm != null) + return false; + } else if (!algorithm.equals(other.algorithm)) + return false; + if (!Arrays.equals(encoded, other.encoded)) + return false; + return true; + } +} |