KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > crmf > SinglePubInfo


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// to whom the Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in all copies or
12
// substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19

20 package com.novosec.pkix.asn1.crmf;
21
22 import org.bouncycastle.asn1.ASN1EncodableVector;
23 import org.bouncycastle.asn1.ASN1Sequence;
24 import org.bouncycastle.asn1.ASN1TaggedObject;
25 import org.bouncycastle.asn1.DEREncodable;
26 import org.bouncycastle.asn1.DERInteger;
27 import org.bouncycastle.asn1.DERObject;
28 import org.bouncycastle.asn1.DERSequence;
29 import org.bouncycastle.asn1.x509.GeneralName;
30
31 /**
32  * ASN.1 structure DER En/DeCoder.
33  *
34  * <pre>
35  * SinglePubInfo ::= SEQUENCE {
36  * pubMethod INTEGER {
37  * dontCare (0),
38  * x500 (1),
39  * web (2),
40  * ldap (3) },
41  * pubLocation GeneralName OPTIONAL }
42  *
43  * </pre>
44  */

45 public class SinglePubInfo implements DEREncodable
46 {
47     DERInteger pubMethod;
48     GeneralName pubLocation;
49
50     public static SinglePubInfo getInstance( ASN1TaggedObject obj, boolean explicit )
51     {
52         return getInstance(ASN1Sequence.getInstance(obj, explicit));
53     }
54
55     public static SinglePubInfo getInstance( Object JavaDoc obj )
56     {
57         if (obj instanceof SinglePubInfo)
58         {
59             return (SinglePubInfo)obj;
60         }
61         else if (obj instanceof ASN1Sequence)
62         {
63             return new SinglePubInfo((ASN1Sequence)obj);
64         }
65
66         throw new IllegalArgumentException JavaDoc("unknown object in factory");
67     }
68     
69     public SinglePubInfo( ASN1Sequence seq )
70     {
71       this.pubMethod = DERInteger.getInstance(seq.getObjectAt(0));
72       
73       if( seq.size()>1 )
74         this.pubLocation = GeneralName.getInstance((ASN1TaggedObject)seq.getObjectAt(1),true); //QQQ ??? choice is always explicit --> true
75
}
76
77     public SinglePubInfo( DERInteger pubMethod )
78     {
79       this.pubMethod = pubMethod;
80     }
81
82     public DERInteger getPubMethod()
83     {
84         return pubMethod;
85     }
86
87     public GeneralName getPubLocation()
88     {
89         return pubLocation;
90     }
91
92     public void setPubLocation(GeneralName pubLocation)
93     {
94       this.pubLocation = pubLocation;
95     }
96
97     public DERObject getDERObject()
98     {
99         ASN1EncodableVector v = new ASN1EncodableVector();
100
101         v.add( pubMethod );
102         
103         if( pubLocation != null )
104           v.add( pubLocation );
105
106         return new DERSequence(v);
107     }
108
109     public String JavaDoc toString()
110     {
111       String JavaDoc s = "SinglePubInfo: (pubMethod = " + this.getPubMethod() + ", ";
112       
113       if( this.getPubLocation() != null )
114         s += "pubLocation = " + this.getPubLocation();
115         
116       s += ")";
117       
118       return s;
119     }
120 }
121
Popular Tags