01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.security.x509;
19:
20: import java.io.IOException;
21:
22: import org.apache.harmony.security.asn1.ASN1OctetString;
23: import org.apache.harmony.security.utils.Array;
24:
25: /**
26: * Subject Key Identifier Extension (OID = 2.5.29.14).
27: *
28: * The ASN.1 definition for extension is:
29: *
30: * <pre>
31: * id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 }
32: *
33: * SubjectKeyIdentifier ::= KeyIdentifier
34: *
35: * KeyIdentifier ::= OCTET STRING
36: * </pre>
37: * (as specified in RFC 3280 http://www.ietf.org/rfc/rfc3280.txt)
38: */
39: public class SubjectKeyIdentifier extends ExtensionValue {
40:
41: // the value of key identifier
42: private final byte[] keyIdentifier;
43:
44: /**
45: * Creates the object on the base of the value of key identifier.
46: */
47: public SubjectKeyIdentifier(byte[] keyIdentifier) {
48: this .keyIdentifier = keyIdentifier;
49: }
50:
51: /**
52: * Creates an object on the base of its encoded form.
53: */
54: public static SubjectKeyIdentifier decode(byte[] encoding)
55: throws IOException {
56: SubjectKeyIdentifier res = new SubjectKeyIdentifier(
57: (byte[]) ASN1OctetString.getInstance().decode(encoding));
58: res.encoding = encoding;
59: return res;
60: }
61:
62: /**
63: * Returns ASN.1 encoded form of extension.
64: * @return a byte array containing ASN.1 encoded form.
65: */
66: public byte[] getEncoded() {
67: if (encoding == null) {
68: encoding = ASN1OctetString.getInstance().encode(
69: keyIdentifier);
70: }
71: return encoding;
72: }
73:
74: /**
75: * Places the string representation of extension value
76: * into the StringBuffer object.
77: */
78: public void dumpValue(StringBuffer buffer, String prefix) {
79: buffer.append(prefix).append("SubjectKeyIdentifier: [\n"); //$NON-NLS-1$
80: buffer.append(Array.toString(keyIdentifier, prefix));
81: buffer.append(prefix).append("]\n"); //$NON-NLS-1$
82: }
83: }
|