KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > pkcs > CertificationRequestInfo


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.pkcs;
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.ASN1Set;
24 import org.apache.geronimo.util.asn1.DERInteger;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.DERSequence;
27 import org.apache.geronimo.util.asn1.DERTaggedObject;
28 import org.apache.geronimo.util.asn1.x509.SubjectPublicKeyInfo;
29 import org.apache.geronimo.util.asn1.x509.X509Name;
30
31 /**
32  * PKCS10 CertificationRequestInfo object.
33  * <pre>
34  * CertificationRequestInfo ::= SEQUENCE {
35  * version INTEGER { v1(0) } (v1,...),
36  * subject Name,
37  * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }},
38  * attributes [0] Attributes{{ CRIAttributes }}
39  * }
40  *
41  * Attributes { ATTRIBUTE:IOSet } ::= SET OF Attribute{{ IOSet }}
42  *
43  * Attribute { ATTRIBUTE:IOSet } ::= SEQUENCE {
44  * type ATTRIBUTE.&id({IOSet}),
45  * values SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{\@type})
46  * }
47  * </pre>
48  */

49 public class CertificationRequestInfo
50     extends ASN1Encodable
51 {
52     DERInteger version = new DERInteger(0);
53     X509Name subject;
54     SubjectPublicKeyInfo subjectPKInfo;
55     ASN1Set attributes = null;
56
57     public static CertificationRequestInfo getInstance(
58         Object JavaDoc obj)
59     {
60         if (obj instanceof CertificationRequestInfo)
61         {
62             return (CertificationRequestInfo)obj;
63         }
64         else if (obj instanceof ASN1Sequence)
65         {
66             return new CertificationRequestInfo((ASN1Sequence)obj);
67         }
68
69         throw new IllegalArgumentException JavaDoc("unknown object in factory");
70     }
71
72     public CertificationRequestInfo(
73         X509Name subject,
74         SubjectPublicKeyInfo pkInfo,
75         ASN1Set attributes)
76     {
77         this.subject = subject;
78         this.subjectPKInfo = pkInfo;
79         this.attributes = attributes;
80
81         if ((subject == null) || (version == null) || (subjectPKInfo == null))
82         {
83             throw new IllegalArgumentException JavaDoc("Not all mandatory fields set in CertificationRequestInfo generator.");
84         }
85     }
86
87     public CertificationRequestInfo(
88         ASN1Sequence seq)
89     {
90         version = (DERInteger)seq.getObjectAt(0);
91
92         subject = X509Name.getInstance(seq.getObjectAt(1));
93         subjectPKInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(2));
94
95         //
96
// some CertificationRequestInfo objects seem to treat this field
97
// as optional.
98
//
99
if (seq.size() > 3)
100         {
101             DERTaggedObject tagobj = (DERTaggedObject)seq.getObjectAt(3);
102             attributes = ASN1Set.getInstance(tagobj, false);
103         }
104
105         if ((subject == null) || (version == null) || (subjectPKInfo == null))
106         {
107             throw new IllegalArgumentException JavaDoc("Not all mandatory fields set in CertificationRequestInfo generator.");
108         }
109     }
110
111     public DERInteger getVersion()
112     {
113         return version;
114     }
115
116     public X509Name getSubject()
117     {
118         return subject;
119     }
120
121     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
122     {
123         return subjectPKInfo;
124     }
125
126     public ASN1Set getAttributes()
127     {
128         return attributes;
129     }
130
131     public DERObject toASN1Object()
132     {
133         ASN1EncodableVector v = new ASN1EncodableVector();
134
135         v.add(version);
136         v.add(subject);
137         v.add(subjectPKInfo);
138
139         if (attributes != null)
140         {
141             v.add(new DERTaggedObject(false, 0, attributes));
142         }
143
144         return new DERSequence(v);
145     }
146 }
147
Popular Tags