summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2013-05-07 08:16:52 -0700
committerKenny Root <kroot@google.com>2013-05-07 08:18:27 -0700
commitbd788522b36f03dc12750c69fd8b3733ef3801bd (patch)
tree893781491e94ce7ec75fe1e0f2fe5968865cb733
parentab4ab99b79b10a157ab313e57dc2d243ebb5cdcf (diff)
downloadlibcore-bd788522b36f03dc12750c69fd8b3733ef3801bd.zip
libcore-bd788522b36f03dc12750c69fd8b3733ef3801bd.tar.gz
libcore-bd788522b36f03dc12750c69fd8b3733ef3801bd.tar.bz2
NativeCrypto: make our own X.509 key class
Make a key class that just holds the encoded key bytes along with the algorithm identifier. Eclipse IDE made the entire class. Change-Id: I40b198e0f01121d77bfd26b3420068700ab69614
-rw-r--r--crypto/src/main/java/org/conscrypt/OpenSSLX509Certificate.java3
-rw-r--r--crypto/src/main/java/org/conscrypt/X509PublicKey.java86
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;
+ }
+}