001: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002: //
003: // Author: Maik Stohn
004: //
005: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
006: // software and associated documentation files (the "Software"), to deal in the Software
007: // without restriction, including without limitation the rights to use, copy, modify, merge,
008: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
009: // to whom the Software is furnished to do so, subject to the following conditions:
010: //
011: // The above copyright notice and this permission notice shall be included in all copies or
012: // substantial portions of the Software.
013: //
014: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
015: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
016: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
018: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
019:
020: package com.novosec.pkix.asn1.crmf;
021:
022: import org.bouncycastle.asn1.ASN1EncodableVector;
023: import org.bouncycastle.asn1.ASN1Sequence;
024: import org.bouncycastle.asn1.ASN1TaggedObject;
025: import org.bouncycastle.asn1.DEREncodable;
026: import org.bouncycastle.asn1.DERInteger;
027: import org.bouncycastle.asn1.DERObject;
028: import org.bouncycastle.asn1.DERSequence;
029: import org.bouncycastle.asn1.x509.GeneralName;
030:
031: /**
032: * ASN.1 structure DER En/DeCoder.
033: *
034: * <pre>
035: * SinglePubInfo ::= SEQUENCE {
036: * pubMethod INTEGER {
037: * dontCare (0),
038: * x500 (1),
039: * web (2),
040: * ldap (3) },
041: * pubLocation GeneralName OPTIONAL }
042: *
043: * </pre>
044: */
045: public class SinglePubInfo implements DEREncodable {
046: DERInteger pubMethod;
047: GeneralName pubLocation;
048:
049: public static SinglePubInfo getInstance(ASN1TaggedObject obj,
050: boolean explicit) {
051: return getInstance(ASN1Sequence.getInstance(obj, explicit));
052: }
053:
054: public static SinglePubInfo getInstance(Object obj) {
055: if (obj instanceof SinglePubInfo) {
056: return (SinglePubInfo) obj;
057: } else if (obj instanceof ASN1Sequence) {
058: return new SinglePubInfo((ASN1Sequence) obj);
059: }
060:
061: throw new IllegalArgumentException("unknown object in factory");
062: }
063:
064: public SinglePubInfo(ASN1Sequence seq) {
065: this .pubMethod = DERInteger.getInstance(seq.getObjectAt(0));
066:
067: if (seq.size() > 1)
068: this .pubLocation = GeneralName.getInstance(
069: (ASN1TaggedObject) seq.getObjectAt(1), true); //QQQ ??? choice is always explicit --> true
070: }
071:
072: public SinglePubInfo(DERInteger pubMethod) {
073: this .pubMethod = pubMethod;
074: }
075:
076: public DERInteger getPubMethod() {
077: return pubMethod;
078: }
079:
080: public GeneralName getPubLocation() {
081: return pubLocation;
082: }
083:
084: public void setPubLocation(GeneralName pubLocation) {
085: this .pubLocation = pubLocation;
086: }
087:
088: public DERObject getDERObject() {
089: ASN1EncodableVector v = new ASN1EncodableVector();
090:
091: v.add(pubMethod);
092:
093: if (pubLocation != null)
094: v.add(pubLocation);
095:
096: return new DERSequence(v);
097: }
098:
099: public String toString() {
100: String s = "SinglePubInfo: (pubMethod = " + this .getPubMethod()
101: + ", ";
102:
103: if (this .getPubLocation() != null)
104: s += "pubLocation = " + this .getPubLocation();
105:
106: s += ")";
107:
108: return s;
109: }
110: }
|