001: package org.bouncycastle.asn1.x500;
002:
003: import org.bouncycastle.asn1.ASN1Choice;
004: import org.bouncycastle.asn1.ASN1Encodable;
005: import org.bouncycastle.asn1.ASN1TaggedObject;
006: import org.bouncycastle.asn1.DERBMPString;
007: import org.bouncycastle.asn1.DEREncodable;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERPrintableString;
010: import org.bouncycastle.asn1.DERString;
011: import org.bouncycastle.asn1.DERT61String;
012: import org.bouncycastle.asn1.DERUTF8String;
013: import org.bouncycastle.asn1.DERUniversalString;
014:
015: public class DirectoryString extends ASN1Encodable implements
016: ASN1Choice, DERString {
017: private DERString string;
018:
019: public static DirectoryString getInstance(Object o) {
020: if (o instanceof DirectoryString) {
021: return (DirectoryString) o;
022: }
023:
024: if (o instanceof DERT61String) {
025: return new DirectoryString((DERT61String) o);
026: }
027:
028: if (o instanceof DERPrintableString) {
029: return new DirectoryString((DERPrintableString) o);
030: }
031:
032: if (o instanceof DERUniversalString) {
033: return new DirectoryString((DERUniversalString) o);
034: }
035:
036: if (o instanceof DERUTF8String) {
037: return new DirectoryString((DERUTF8String) o);
038: }
039:
040: if (o instanceof DERBMPString) {
041: return new DirectoryString((DERBMPString) o);
042: }
043:
044: throw new IllegalArgumentException(
045: "illegal object in getInstance");
046: }
047:
048: public static DirectoryString getInstance(ASN1TaggedObject o,
049: boolean explicit) {
050: if (!explicit) {
051: throw new IllegalArgumentException(
052: "choice item must be explicitly tagged");
053: }
054:
055: return getInstance(o.getObject());
056: }
057:
058: private DirectoryString(DERT61String string) {
059: this .string = string;
060: }
061:
062: private DirectoryString(DERPrintableString string) {
063: this .string = string;
064: }
065:
066: private DirectoryString(DERUniversalString string) {
067: this .string = string;
068: }
069:
070: private DirectoryString(DERUTF8String string) {
071: this .string = string;
072: }
073:
074: private DirectoryString(DERBMPString string) {
075: this .string = string;
076: }
077:
078: public DirectoryString(String string) {
079: this .string = new DERUTF8String(string);
080: }
081:
082: public String getString() {
083: return string.getString();
084: }
085:
086: public String toString() {
087: return string.getString();
088: }
089:
090: /**
091: * <pre>
092: * DirectoryString ::= CHOICE {
093: * teletexString TeletexString (SIZE (1..MAX)),
094: * printableString PrintableString (SIZE (1..MAX)),
095: * universalString UniversalString (SIZE (1..MAX)),
096: * utf8String UTF8String (SIZE (1..MAX)),
097: * bmpString BMPString (SIZE (1..MAX)) }
098: * </pre>
099: */
100: public DERObject toASN1Object() {
101: return ((DEREncodable) string).getDERObject();
102: }
103: }
|