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.ASN1Explicit;
024: import org.apache.harmony.security.asn1.ASN1Sequence;
025: import org.apache.harmony.security.asn1.ASN1Type;
026: import org.apache.harmony.security.asn1.BerInputStream;
027: import org.apache.harmony.security.x501.DirectoryString;
028:
029: /**
030: * The class encapsulates the ASN.1 DER encoding/decoding work
031: * with the following structure which is a subpart of GeneralName
032: * (as specified in RFC 3280 -
033: * Internet X.509 Public Key Infrastructure.
034: * Certificate and Certificate Revocation List (CRL) Profile.
035: * http://www.ietf.org/rfc/rfc3280.txt):
036: *
037: * <pre>
038: * EDIPartyName ::= SEQUENCE {
039: * nameAssigner [0] DirectoryString OPTIONAL,
040: * partyName [1] DirectoryString
041: * }
042: *
043: * DirectoryString ::= CHOICE {
044: * teletexString TeletexString (SIZE (1..MAX)),
045: * printableString PrintableString (SIZE (1..MAX)),
046: * universalString UniversalString (SIZE (1..MAX)),
047: * utf8String UTF8String (SIZE (1..MAX)),
048: * bmpString BMPString (SIZE (1..MAX))
049: * }
050: * </pre>
051: */
052: public class EDIPartyName {
053: // the value of nameAssigner field of the structure
054: private String nameAssigner;
055: // the value of partyName field of the structure
056: private String partyName;
057: // the ASN.1 encoded form of EDIPartyName
058: private byte[] encoding;
059:
060: /**
061: * TODO
062: * @param nameAssigner: String
063: * @param partyName: String
064: */
065: public EDIPartyName(String nameAssigner, String partyName) {
066: this .nameAssigner = nameAssigner;
067: this .partyName = partyName;
068: }
069:
070: //
071: // TODO
072: // @param nameAssigner: String
073: // @param partyName: String
074: // @param encoding: byte[]
075: //
076: private EDIPartyName(String nameAssigner, String partyName,
077: byte[] encoding) {
078: this .nameAssigner = nameAssigner;
079: this .partyName = partyName;
080: this .encoding = encoding;
081: }
082:
083: /**
084: * Returns the value of nameAssigner field of the structure.
085: * @return nameAssigner
086: */
087: public String getNameAssigner() {
088: return nameAssigner;
089: }
090:
091: /**
092: * Returns the value of partyName field of the structure.
093: * @return partyName
094: */
095: public String getPartyName() {
096: return partyName;
097: }
098:
099: /**
100: * Returns ASN.1 encoded form of this X.509 EDIPartyName value.
101: * @return a byte array containing ASN.1 encode form.
102: */
103: public byte[] getEncoded() {
104: if (encoding == null) {
105: encoding = ASN1.encode(this );
106: }
107: return encoding;
108: }
109:
110: /**
111: * ASN.1 DER X.509 EDIPartyName encoder/decoder class.
112: */
113: public static final ASN1Sequence ASN1 = new ASN1Sequence(
114: new ASN1Type[] { new ASN1Explicit(0, DirectoryString.ASN1),
115: new ASN1Explicit(1, DirectoryString.ASN1) }) {
116: {
117: setOptional(0);
118: }
119:
120: protected Object getDecodedObject(BerInputStream in) {
121: Object[] values = (Object[]) in.content;
122: return new EDIPartyName((String) values[0],
123: (String) values[1], in.getEncoded());
124: }
125:
126: protected void getValues(Object object, Object[] values) {
127: EDIPartyName epn = (EDIPartyName) object;
128: values[0] = epn.nameAssigner;
129: values[1] = epn.partyName;
130: }
131: };
132: }
|