diff options
author | Kenny Root <kroot@google.com> | 2014-05-07 19:37:08 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-05-07 19:37:08 +0000 |
commit | 982fb06853ed14a38dbf300f633b8a5c9ef6a722 (patch) | |
tree | f80f19271000bdad38aebed04a390ca33ee7f373 /luni/src | |
parent | 91a37e34633fd33dc342724bcfcf2dcd76c4a511 (diff) | |
parent | 14f4875cedd807a57aacad981ec083cfa3326f03 (diff) | |
download | libcore-982fb06853ed14a38dbf300f633b8a5c9ef6a722.zip libcore-982fb06853ed14a38dbf300f633b8a5c9ef6a722.tar.gz libcore-982fb06853ed14a38dbf300f633b8a5c9ef6a722.tar.bz2 |
am 14f4875c: am db3cbbc3: Merge "Add java.security.cert.Extension interface"
* commit '14f4875cedd807a57aacad981ec083cfa3326f03':
Add java.security.cert.Extension interface
Diffstat (limited to 'luni/src')
3 files changed, 83 insertions, 9 deletions
diff --git a/luni/src/main/java/java/security/cert/Extension.java b/luni/src/main/java/java/security/cert/Extension.java new file mode 100644 index 0000000..8013809 --- /dev/null +++ b/luni/src/main/java/java/security/cert/Extension.java @@ -0,0 +1,65 @@ +/* + * Copyright 2014 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 java.security.cert; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * The Extension part of an X.509 certificate (as specified in <a + * href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280 — Internet X.509 + * Public Key Infrastructure: Certificate and Certificate Revocation List (CRL) + * Profile</p>): + * + * <pre> + * Extension ::= SEQUENCE { + * extnID OBJECT IDENTIFIER, + * critical BOOLEAN DEFAULT FALSE, + * extnValue OCTET STRING + * } + * </pre> + * + * @since 1.7 + * @hide + */ +public interface Extension { + /** + * Returns the OID (Object Identifier) for this extension encoded as a + * string (e.g., "2.5.29.15"). + */ + String getId(); + + /** + * Returns {@code true} if this extension is critical. If this is true and + * an implementation does not understand this extension, it must reject it. + * See RFC 3280 section 4.2 for more information. + */ + boolean isCritical(); + + /** + * The DER-encoded value of this extension. + */ + byte[] getValue(); + + /** + * Writes the DER-encoded extension to {@code out}. + * + * @throws IOException when there is an encoding error or error writing to + * {@code out} + */ + void encode(OutputStream out) throws IOException; +} diff --git a/luni/src/main/java/org/apache/harmony/security/x509/Extension.java b/luni/src/main/java/org/apache/harmony/security/x509/Extension.java index d9b02f9..d5d8015 100644 --- a/luni/src/main/java/org/apache/harmony/security/x509/Extension.java +++ b/luni/src/main/java/org/apache/harmony/security/x509/Extension.java @@ -23,6 +23,7 @@ package org.apache.harmony.security.x509; import java.io.IOException; +import java.io.OutputStream; import java.util.Arrays; import org.apache.harmony.security.asn1.ASN1Boolean; import org.apache.harmony.security.asn1.ASN1OctetString; @@ -49,7 +50,7 @@ import org.apache.harmony.security.utils.Array; * } * </pre> */ -public final class Extension { +public final class Extension implements java.security.cert.Extension { // critical constants public static final boolean CRITICAL = true; public static final boolean NON_CRITICAL = false; @@ -145,7 +146,8 @@ public final class Extension { /** * Returns the value of extnID field of the structure. */ - public String getExtnID() { + @Override + public String getId() { if (extnID_str == null) { extnID_str = ObjectIdentifier.toString(extnID); } @@ -155,14 +157,16 @@ public final class Extension { /** * Returns the value of critical field of the structure. */ - public boolean getCritical() { + @Override + public boolean isCritical() { return critical; } /** * Returns the value of extnValue field of the structure. */ - public byte[] getExtnValue() { + @Override + public byte[] getValue() { return extnValue; } @@ -187,6 +191,11 @@ public final class Extension { return encoding; } + @Override + public void encode(OutputStream out) throws IOException { + out.write(getEncoded()); + } + @Override public boolean equals(Object ext) { if (!(ext instanceof Extension)) { return false; @@ -287,7 +296,7 @@ public final class Extension { } public void dumpValue(StringBuilder sb, String prefix) { - sb.append("OID: ").append(getExtnID()).append(", Critical: ").append(critical).append('\n'); + sb.append("OID: ").append(getId()).append(", Critical: ").append(critical).append('\n'); if (!valueDecoded) { try { decodeExtensionValue(); diff --git a/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java b/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java index 92ff3a9..7a10ebc 100644 --- a/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java +++ b/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java @@ -136,8 +136,8 @@ public final class Extensions { Set<String> localNoncritical = new HashSet<String>(size); Boolean localHasUnsupported = Boolean.FALSE; for (Extension extension : extensions) { - String oid = extension.getExtnID(); - if (extension.getCritical()) { + String oid = extension.getId(); + if (extension.isCritical()) { if (!SUPPORTED_CRITICAL.contains(oid)) { localHasUnsupported = Boolean.TRUE; } @@ -162,7 +162,7 @@ public final class Extensions { if (localOidMap == null) { localOidMap = new HashMap<String, Extension>(); for (Extension extension : extensions) { - localOidMap.put(extension.getExtnID(), extension); + localOidMap.put(extension.getId(), extension); } this.oidMap = localOidMap; } @@ -311,7 +311,7 @@ public final class Extensions { } Collection<List<?>> collection = ((GeneralNames) GeneralNames.ASN1.decode(extension - .getExtnValue())).getPairsList(); + .getValue())).getPairsList(); /* * If the extension had any invalid entries, we may have an empty |