Commit 7d97b2ce authored by Kenny Root's avatar Kenny Root
Browse files

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
parent ad89c529
......@@ -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
......
/*
* 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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment