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 18/** 19* @author Alexander Y. Kleymenov 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.x509; 24 25import org.apache.harmony.security.asn1.ASN1Any; 26import org.apache.harmony.security.asn1.ASN1Explicit; 27import org.apache.harmony.security.asn1.ASN1Oid; 28import org.apache.harmony.security.asn1.ASN1Sequence; 29import org.apache.harmony.security.asn1.ASN1Type; 30import org.apache.harmony.security.asn1.BerInputStream; 31import org.apache.harmony.security.asn1.ObjectIdentifier; 32 33/** 34 * The class encapsulates the ASN.1 DER encoding/decoding work 35 * with OtherName structure which is a subpart of GeneralName 36 * (as specified in RFC 3280 - 37 * Internet X.509 Public Key Infrastructure. 38 * Certificate and Certificate Revocation List (CRL) Profile. 39 * http://www.ietf.org/rfc/rfc3280.txt): 40 * 41 * <pre> 42 * OtherName ::= SEQUENCE { 43 * type-id OBJECT IDENTIFIER, 44 * value [0] EXPLICIT ANY DEFINED BY type-id 45 * } 46 * </pre> 47 */ 48public class OtherName { 49 // the value of typeID field of the structure 50 private String typeID; 51 // the value of value field of the structure 52 private byte[] value; 53 // the ASN.1 encoded form of OtherName 54 private byte[] encoding; 55 56 /** 57 * TODO 58 * @param typeID: String 59 * @param value: byte[] 60 */ 61 public OtherName(String typeID, byte[] value) { 62 this(typeID, value, null); 63 } 64 65 // 66 // TODO 67 // @param typeID: String 68 // @param value: byte[] 69 // @param encoding: byte[] 70 // 71 private OtherName(String typeID, byte[] value, byte[] encoding) { 72 this.typeID = typeID; 73 this.value = value; 74 this.encoding = encoding; 75 } 76 77 /** 78 * Returns the value of typeID field of the structure. 79 * @return typeID 80 */ 81 public String getTypeID() { 82 return typeID; 83 } 84 85 /** 86 * Returns the value of value field of the structure. 87 * @return value 88 */ 89 public byte[] getValue() { 90 return value; 91 } 92 93 /** 94 * Returns ASN.1 encoded form of this X.509 OtherName value. 95 * @return a byte array containing ASN.1 encode form. 96 */ 97 public byte[] getEncoded() { 98 if (encoding == null) { 99 encoding = ASN1.encode(this); 100 } 101 return encoding; 102 } 103 104 /** 105 * ASN.1 DER X.509 OtherName encoder/decoder class. 106 */ 107 public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { 108 ASN1Oid.getInstance(), 109 new ASN1Explicit(0, ASN1Any.getInstance()) }) { 110 111 protected Object getDecodedObject(BerInputStream in) { 112 Object[] values = (Object[]) in.content; 113 return new OtherName(ObjectIdentifier.toString((int[]) values[0]), 114 (byte[]) values[1], in.getEncoded()); 115 } 116 117 protected void getValues(Object object, Object[] values) { 118 119 OtherName on = (OtherName) object; 120 121 values[0] = ObjectIdentifier.toIntArray(on.typeID); 122 values[1] = on.value; 123 } 124 }; 125} 126 127