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.ASN1Explicit; 26import org.apache.harmony.security.asn1.ASN1Sequence; 27import org.apache.harmony.security.asn1.ASN1Type; 28import org.apache.harmony.security.asn1.BerInputStream; 29import org.apache.harmony.security.x501.DirectoryString; 30 31/** 32 * The class encapsulates the ASN.1 DER encoding/decoding work 33 * with the following structure which is a subpart of GeneralName 34 * (as specified in RFC 3280 - 35 * Internet X.509 Public Key Infrastructure. 36 * Certificate and Certificate Revocation List (CRL) Profile. 37 * http://www.ietf.org/rfc/rfc3280.txt): 38 * 39 * <pre> 40 * EDIPartyName ::= SEQUENCE { 41 * nameAssigner [0] DirectoryString OPTIONAL, 42 * partyName [1] DirectoryString 43 * } 44 * 45 * DirectoryString ::= CHOICE { 46 * teletexString TeletexString (SIZE (1..MAX)), 47 * printableString PrintableString (SIZE (1..MAX)), 48 * universalString UniversalString (SIZE (1..MAX)), 49 * utf8String UTF8String (SIZE (1..MAX)), 50 * bmpString BMPString (SIZE (1..MAX)) 51 * } 52 * </pre> 53 */ 54public class EDIPartyName { 55 // the value of nameAssigner field of the structure 56 private String nameAssigner; 57 // the value of partyName field of the structure 58 private String partyName; 59 // the ASN.1 encoded form of EDIPartyName 60 private byte[] encoding; 61 62 /** 63 * TODO 64 * @param nameAssigner: String 65 * @param partyName: String 66 */ 67 public EDIPartyName(String nameAssigner, String partyName) { 68 this.nameAssigner = nameAssigner; 69 this.partyName = partyName; 70 } 71 72 // 73 // TODO 74 // @param nameAssigner: String 75 // @param partyName: String 76 // @param encoding: byte[] 77 // 78 private EDIPartyName(String nameAssigner, String partyName, 79 byte[] encoding) { 80 this.nameAssigner = nameAssigner; 81 this.partyName = partyName; 82 this.encoding = encoding; 83 } 84 85 /** 86 * Returns the value of nameAssigner field of the structure. 87 * @return nameAssigner 88 */ 89 public String getNameAssigner() { 90 return nameAssigner; 91 } 92 93 /** 94 * Returns the value of partyName field of the structure. 95 * @return partyName 96 */ 97 public String getPartyName() { 98 return partyName; 99 } 100 101 /** 102 * Returns ASN.1 encoded form of this X.509 EDIPartyName value. 103 * @return a byte array containing ASN.1 encode form. 104 */ 105 public byte[] getEncoded() { 106 if (encoding == null) { 107 encoding = ASN1.encode(this); 108 } 109 return encoding; 110 } 111 112 /** 113 * ASN.1 DER X.509 EDIPartyName encoder/decoder class. 114 */ 115 public static final ASN1Sequence ASN1 = new ASN1Sequence( 116 new ASN1Type[] { 117 new ASN1Explicit(0, DirectoryString.ASN1), 118 new ASN1Explicit(1, DirectoryString.ASN1) 119 }) { 120 { 121 setOptional(0); 122 } 123 124 protected Object getDecodedObject(BerInputStream in) { 125 Object[] values = (Object[]) in.content; 126 return new EDIPartyName((String) values[0], (String) values[1], 127 in.getEncoded()); 128 } 129 130 protected void getValues(Object object, Object[] values) { 131 EDIPartyName epn = (EDIPartyName) object; 132 values[0] = epn.nameAssigner; 133 values[1] = epn.partyName; 134 } 135 }; 136} 137