KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > IssuerSerial


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 package org.apache.geronimo.util.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.ASN1Sequence;
23 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
24 import org.apache.geronimo.util.asn1.DERBitString;
25 import org.apache.geronimo.util.asn1.DERInteger;
26 import org.apache.geronimo.util.asn1.DERObject;
27 import org.apache.geronimo.util.asn1.DERSequence;
28
29 public class IssuerSerial
30     extends ASN1Encodable
31 {
32     GeneralNames issuer;
33     DERInteger serial;
34     DERBitString issuerUID;
35
36     public static IssuerSerial getInstance(
37             Object JavaDoc obj)
38     {
39         if (obj == null || obj instanceof GeneralNames)
40         {
41             return (IssuerSerial)obj;
42         }
43
44         if (obj instanceof ASN1Sequence)
45         {
46             return new IssuerSerial((ASN1Sequence)obj);
47         }
48
49         throw new IllegalArgumentException JavaDoc("illegal object in getInstance: " + obj.getClass().getName());
50     }
51
52     public static IssuerSerial getInstance(
53         ASN1TaggedObject obj,
54         boolean explicit)
55     {
56         return getInstance(ASN1Sequence.getInstance(obj, explicit));
57     }
58
59     public IssuerSerial(
60         ASN1Sequence seq)
61     {
62         issuer = GeneralNames.getInstance(seq.getObjectAt(0));
63         serial = (DERInteger)seq.getObjectAt(1);
64
65         if (seq.size() == 3)
66         {
67             issuerUID = (DERBitString)seq.getObjectAt(2);
68         }
69     }
70
71     public IssuerSerial(
72         GeneralNames issuer,
73         DERInteger serial)
74     {
75         this.issuer = issuer;
76         this.serial = serial;
77     }
78
79     public GeneralNames getIssuer()
80     {
81         return issuer;
82     }
83
84     public DERInteger getSerial()
85     {
86         return serial;
87     }
88
89     public DERBitString getIssuerUID()
90     {
91         return issuerUID;
92     }
93
94     /**
95      * Produce an object suitable for an ASN1OutputStream.
96      * <pre>
97      * IssuerSerial ::= SEQUENCE {
98      * issuer GeneralNames,
99      * serial CertificateSerialNumber,
100      * issuerUID UniqueIdentifier OPTIONAL
101      * }
102      * </pre>
103      */

104     public DERObject toASN1Object()
105     {
106         ASN1EncodableVector v = new ASN1EncodableVector();
107
108         v.add(issuer);
109         v.add(serial);
110
111         if (issuerUID != null)
112         {
113             v.add(issuerUID);
114         }
115
116         return new DERSequence(v);
117     }
118 }
119
Popular Tags