1
package org.bouncycastle.asn1.esf;
3
import java.util.Enumeration;
5
import org.bouncycastle.asn1.ASN1Encodable;
6
import org.bouncycastle.asn1.ASN1EncodableVector;
7
import org.bouncycastle.asn1.ASN1Sequence;
8
import org.bouncycastle.asn1.DERObject;
9
import org.bouncycastle.asn1.DERSequence;
10
import org.bouncycastle.asn1.DERTaggedObject;
11
import org.bouncycastle.asn1.DERUTF8String;
12
import org.bouncycastle.asn1.x500.DirectoryString;
15
* Signer-Location attribute (RFC3126).
18
* SignerLocation ::= SEQUENCE {
19
* countryName [0] DirectoryString OPTIONAL,
20
* localityName [1] DirectoryString OPTIONAL,
21
* postalAddress [2] PostalAddress OPTIONAL }
23
* PostalAddress ::= SEQUENCE SIZE(1..6) OF DirectoryString
26
public class SignerLocation
29
private DERUTF8String countryName;
30
private DERUTF8String localityName;
31
private ASN1Sequence postalAddress;
33
public SignerLocation(
36
Enumeration e = seq.getObjects();
38
while (e.hasMoreElements())
40
DERTaggedObject o = (DERTaggedObject)e.nextElement();
45
DirectoryString countryNameDirectoryString = DirectoryString.getInstance(o, true);
46
this.countryName = new DERUTF8String(countryNameDirectoryString.getString());
49
DirectoryString localityNameDirectoryString = DirectoryString.getInstance(o, true);
50
this.localityName = new DERUTF8String(localityNameDirectoryString.getString());
55
this.postalAddress = ASN1Sequence.getInstance(o, true);
57
else // handle erroneous implicitly tagged sequences
59
this.postalAddress = ASN1Sequence.getInstance(o, false);
61
if (postalAddress != null && postalAddress.size() > 6)
63
throw new IllegalArgumentException("postal address must contain less than 6 strings");
67
throw new IllegalArgumentException("illegal tag");
72
public SignerLocation(
73
DERUTF8String countryName,
74
DERUTF8String localityName,
75
ASN1Sequence postalAddress)
77
if (postalAddress != null && postalAddress.size() > 6)
79
throw new IllegalArgumentException("postal address must contain less than 6 strings");
82
if (countryName != null)
84
this.countryName = DERUTF8String.getInstance(countryName.toASN1Object());
87
if (localityName != null)
89
this.localityName = DERUTF8String.getInstance(localityName.toASN1Object());
92
if (postalAddress != null)
94
this.postalAddress = ASN1Sequence.getInstance(postalAddress.toASN1Object());
98
public static SignerLocation getInstance(
101
if (obj == null || obj instanceof SignerLocation)
103
return (SignerLocation)obj;
106
return new SignerLocation(ASN1Sequence.getInstance(obj));
109
public DERUTF8String getCountryName()
114
public DERUTF8String getLocalityName()
119
public ASN1Sequence getPostalAddress()
121
return postalAddress;
126
* SignerLocation ::= SEQUENCE {
127
* countryName [0] DirectoryString OPTIONAL,
128
* localityName [1] DirectoryString OPTIONAL,
129
* postalAddress [2] PostalAddress OPTIONAL }
131
* PostalAddress ::= SEQUENCE SIZE(1..6) OF DirectoryString
133
* DirectoryString ::= CHOICE {
134
* teletexString TeletexString (SIZE (1..MAX)),
135
* printableString PrintableString (SIZE (1..MAX)),
136
* universalString UniversalString (SIZE (1..MAX)),
137
* utf8String UTF8String (SIZE (1.. MAX)),
138
* bmpString BMPString (SIZE (1..MAX)) }
141
public DERObject toASN1Object()
143
ASN1EncodableVector v = new ASN1EncodableVector();
145
if (countryName != null)
147
v.add(new DERTaggedObject(true, 0, countryName));
150
if (localityName != null)
152
v.add(new DERTaggedObject(true, 1, localityName));
155
if (postalAddress != null)
157
v.add(new DERTaggedObject(true, 2, postalAddress));
160
return new DERSequence(v);
b'\\ No newline at end of file'