001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.security.x509;
022:
023: import org.apache.harmony.security.asn1.ASN1Any;
024: import org.apache.harmony.security.asn1.ASN1Explicit;
025: import org.apache.harmony.security.asn1.ASN1Oid;
026: import org.apache.harmony.security.asn1.ASN1Sequence;
027: import org.apache.harmony.security.asn1.ASN1Type;
028: import org.apache.harmony.security.asn1.BerInputStream;
029: import org.apache.harmony.security.asn1.ObjectIdentifier;
030:
031: /**
032: * The class encapsulates the ASN.1 DER encoding/decoding work
033: * with OtherName structure which is a subpart of GeneralName
034: * (as specified in RFC 3280 -
035: * Internet X.509 Public Key Infrastructure.
036: * Certificate and Certificate Revocation List (CRL) Profile.
037: * http://www.ietf.org/rfc/rfc3280.txt):
038: *
039: * <pre>
040: * OtherName ::= SEQUENCE {
041: * type-id OBJECT IDENTIFIER,
042: * value [0] EXPLICIT ANY DEFINED BY type-id
043: * }
044: * </pre>
045: */
046: public class OtherName {
047: // the value of typeID field of the structure
048: private String typeID;
049: // the value of value field of the structure
050: private byte[] value;
051: // the ASN.1 encoded form of OtherName
052: private byte[] encoding;
053:
054: /**
055: * TODO
056: * @param typeID: String
057: * @param value: byte[]
058: */
059: public OtherName(String typeID, byte[] value) {
060: this (typeID, value, null);
061: }
062:
063: //
064: // TODO
065: // @param typeID: String
066: // @param value: byte[]
067: // @param encoding: byte[]
068: //
069: private OtherName(String typeID, byte[] value, byte[] encoding) {
070: this .typeID = typeID;
071: this .value = value;
072: this .encoding = encoding;
073: }
074:
075: /**
076: * Returns the value of typeID field of the structure.
077: * @return typeID
078: */
079: public String getTypeID() {
080: return typeID;
081: }
082:
083: /**
084: * Returns the value of value field of the structure.
085: * @return value
086: */
087: public byte[] getValue() {
088: return value;
089: }
090:
091: /**
092: * Returns ASN.1 encoded form of this X.509 OtherName value.
093: * @return a byte array containing ASN.1 encode form.
094: */
095: public byte[] getEncoded() {
096: if (encoding == null) {
097: encoding = ASN1.encode(this );
098: }
099: return encoding;
100: }
101:
102: /**
103: * ASN.1 DER X.509 OtherName encoder/decoder class.
104: */
105: public static final ASN1Sequence ASN1 = new ASN1Sequence(
106: new ASN1Type[] { ASN1Oid.getInstance(),
107: new ASN1Explicit(0, ASN1Any.getInstance()) }) {
108:
109: protected Object getDecodedObject(BerInputStream in) {
110: Object[] values = (Object[]) in.content;
111: return new OtherName(ObjectIdentifier
112: .toString((int[]) values[0]), (byte[]) values[1],
113: in.getEncoded());
114: }
115:
116: protected void getValues(Object object, Object[] values) {
117:
118: OtherName on = (OtherName) object;
119:
120: values[0] = ObjectIdentifier.toIntArray(on.typeID);
121: values[1] = on.value;
122: }
123: };
124: }
|