KickJava   Java API By Example, From Geeks To Geeks.

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


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 AttributeCertificateInfo
30     extends ASN1Encodable
31 {
32     private DERInteger version;
33     private Holder holder;
34     private AttCertIssuer issuer;
35     private AlgorithmIdentifier signature;
36     private DERInteger serialNumber;
37     private AttCertValidityPeriod attrCertValidityPeriod;
38     private ASN1Sequence attributes;
39     private DERBitString issuerUniqueID;
40     private X509Extensions extensions;
41
42     public static AttributeCertificateInfo getInstance(
43         ASN1TaggedObject obj,
44         boolean explicit)
45     {
46         return getInstance(ASN1Sequence.getInstance(obj, explicit));
47     }
48
49     public static AttributeCertificateInfo getInstance(
50         Object JavaDoc obj)
51     {
52         if (obj instanceof AttributeCertificateInfo)
53         {
54             return (AttributeCertificateInfo)obj;
55         }
56         else if (obj instanceof ASN1Sequence)
57         {
58             return new AttributeCertificateInfo((ASN1Sequence)obj);
59         }
60
61         throw new IllegalArgumentException JavaDoc("unknown object in factory");
62     }
63
64     public AttributeCertificateInfo(
65         ASN1Sequence seq)
66     {
67         this.version = DERInteger.getInstance(seq.getObjectAt(0));
68         this.holder = Holder.getInstance(seq.getObjectAt(1));
69         this.issuer = AttCertIssuer.getInstance(seq.getObjectAt(2));
70         this.signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(3));
71         this.serialNumber = DERInteger.getInstance(seq.getObjectAt(4));
72         this.attrCertValidityPeriod = AttCertValidityPeriod.getInstance(seq.getObjectAt(5));
73         this.attributes = ASN1Sequence.getInstance(seq.getObjectAt(6));
74
75         for (int i = 7; i < seq.size(); i++)
76         {
77             ASN1Encodable obj = (ASN1Encodable)seq.getObjectAt(i);
78
79             if (obj instanceof DERBitString)
80             {
81                 this.issuerUniqueID = DERBitString.getInstance(seq.getObjectAt(i));
82             }
83             else if (obj instanceof ASN1Sequence || obj instanceof X509Extensions)
84             {
85                 this.extensions = X509Extensions.getInstance(seq.getObjectAt(i));
86             }
87         }
88     }
89
90     public DERInteger getVersion()
91     {
92         return version;
93     }
94
95     public Holder getHolder()
96     {
97         return holder;
98     }
99
100     public AttCertIssuer getIssuer()
101     {
102         return issuer;
103     }
104
105     public AlgorithmIdentifier getSignature()
106     {
107         return signature;
108     }
109
110     public DERInteger getSerialNumber()
111     {
112         return serialNumber;
113     }
114
115     public AttCertValidityPeriod getAttrCertValidityPeriod()
116     {
117         return attrCertValidityPeriod;
118     }
119
120     public ASN1Sequence getAttributes()
121     {
122         return attributes;
123     }
124
125     public DERBitString getIssuerUniqueID()
126     {
127         return issuerUniqueID;
128     }
129
130     public X509Extensions getExtensions()
131     {
132         return extensions;
133     }
134
135     /**
136      * Produce an object suitable for an ASN1OutputStream.
137      * <pre>
138      * AttributeCertificateInfo ::= SEQUENCE {
139      * version AttCertVersion -- version is v2,
140      * holder Holder,
141      * issuer AttCertIssuer,
142      * signature AlgorithmIdentifier,
143      * serialNumber CertificateSerialNumber,
144      * attrCertValidityPeriod AttCertValidityPeriod,
145      * attributes SEQUENCE OF Attribute,
146      * issuerUniqueID UniqueIdentifier OPTIONAL,
147      * extensions Extensions OPTIONAL
148      * }
149      *
150      * AttCertVersion ::= INTEGER { v2(1) }
151      * </pre>
152      */

153     public DERObject toASN1Object()
154     {
155         ASN1EncodableVector v = new ASN1EncodableVector();
156
157         v.add(version);
158         v.add(holder);
159         v.add(issuer);
160         v.add(signature);
161         v.add(serialNumber);
162         v.add(attrCertValidityPeriod);
163         v.add(attributes);
164
165         if (issuerUniqueID != null)
166         {
167             v.add(issuerUniqueID);
168         }
169
170         if (extensions != null)
171         {
172             v.add(extensions);
173         }
174
175         return new DERSequence(v);
176     }
177 }
178
Popular Tags