SubjectKeyIdentifier.java revision fd6bb3510c2f94d636f3572dcf5f7f4dcd1a2726
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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 18package org.apache.harmony.security.x509; 19 20import java.io.IOException; 21 22import org.apache.harmony.security.asn1.ASN1OctetString; 23import 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 */ 39public 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((byte[]) 57 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(keyIdentifier); 69 } 70 return encoding; 71 } 72 73 /** 74 * Places the string representation of extension value 75 * into the StringBuffer object. 76 */ 77 public void dumpValue(StringBuffer buffer, String prefix) { 78 buffer.append(prefix).append("SubjectKeyIdentifier: [\n"); 79 buffer.append(Array.toString(keyIdentifier, prefix)); 80 buffer.append(prefix).append("]\n"); 81 } 82} 83 84