AttCertIssuer | Line # 90 | 45 | 18 | 62.2% |
0.6219512
|
(1) | |||
Result | |||
0.5487805
|
issrg.test.ds.TestDS.testIssuing issrg.test.ds.TestDS.testIssuing | 1 PASS | |
1 | /* | |
2 | * Copyright (c) 2000-2005, University of Salford | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * Redistributions of source code must retain the above copyright notice, this | |
9 | * list of conditions and the following disclaimer. | |
10 | * | |
11 | * Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
14 | * | |
15 | * Neither the name of the University of Salford nor the names of its | |
16 | * contributors may be used to endorse or promote products derived from this | |
17 | * software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | /* | |
32 | * Copyright (c) 2006, University of Kent | |
33 | * All rights reserved. | |
34 | * | |
35 | * Redistribution and use in source and binary forms, with or without | |
36 | * modification, are permitted provided that the following conditions are met: | |
37 | * | |
38 | * Redistributions of source code must retain the above copyright notice, this | |
39 | * list of conditions and the following disclaimer. | |
40 | * | |
41 | * Redistributions in binary form must reproduce the above copyright notice, | |
42 | * this list of conditions and the following disclaimer in the documentation | |
43 | * and/or other materials provided with the distribution. | |
44 | * | |
45 | * 1. Neither the name of the University of Kent nor the names of its | |
46 | * contributors may be used to endorse or promote products derived from this | |
47 | * software without specific prior written permission. | |
48 | * | |
49 | * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
50 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
51 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
52 | * PURPOSE ARE DISCLAIMED. | |
53 | * | |
54 | * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
55 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
56 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
57 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
58 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
59 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
60 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
61 | * POSSIBILITY OF SUCH DAMAGE. | |
62 | * | |
63 | * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE | |
64 | * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS | |
65 | * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS | |
66 | * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH | |
67 | * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH | |
68 | * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY | |
69 | * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE | |
70 | * SERIOUS FAULTS, IN THIS SOFTWARE. | |
71 | * | |
72 | * 5. This license is governed, except to the extent that local laws | |
73 | * necessarily apply, by the laws of England and Wales. | |
74 | */ | |
75 | ||
76 | package issrg.ac; | |
77 | ||
78 | ||
79 | // set CHOICE to either of two _CIDs, or at least one of two values to non-null value | |
80 | ||
81 | import iaik.asn1.*; | |
82 | import iaik.asn1.structures.*; | |
83 | ||
84 | ||
85 | /** | |
86 | * This class represents the AttCertIssuer ASN.1 construct. Set CHOICE value to | |
87 | * either GENERALNAMES_CID, or V1FORM_CID (the same as GENERALNAMES_CID), or | |
88 | * V2FORM_CID, if you provide both v1form and v2form objects to the constructor. | |
89 | */ | |
90 | public class AttCertIssuer implements ASN1Type, Cloneable{ | |
91 | final public static int GENERALNAMES_CID = 0; | |
92 | final public static int V1FORM_CID = GENERALNAMES_CID; | |
93 | final public static int V2FORM_CID = 1; | |
94 | ||
95 | final private static int V2FORM_TAG = 0; | |
96 | ||
97 | protected int CHOICE = -1; | |
98 | ||
99 | /** | |
100 | * Returns the CHOICE setting. | |
101 | * | |
102 | * @see #setChoice(int) | |
103 | */ | |
104 | 0 | public int getChoice(){ |
105 | 0 | return CHOICE; |
106 | } | |
107 | ||
108 | /** | |
109 | * Sets the CHOICE setting. If it equals to GENERALNAMES_CID, the object will | |
110 | * be encoded as GeneralNames | |
111 | * construct; if it equals to V2FORM_CID, the object will be encoded as a | |
112 | * V2Form. | |
113 | * Otherwise a run-time exception will occur at encoding time. | |
114 | * | |
115 | * <p>Note that the CHOICE is set automatically after decoding a BER and if | |
116 | * you pass at least one | |
117 | * non-null parameter to the constructor. | |
118 | * | |
119 | * @param the integer value for CHOICE | |
120 | */ | |
121 | 20 | public void setChoice(int choice){ |
122 | 20 | CHOICE=choice; |
123 | } | |
124 | ||
125 | protected GeneralNames v1Form = null; | |
126 | ||
127 | /** | |
128 | * Returns the value for V1 encoding (GeneralNames choice). | |
129 | */ | |
130 | 2520 | public GeneralNames getV1Form(){ |
131 | 2520 | return v1Form; |
132 | } | |
133 | ||
134 | /** | |
135 | * Sets the value for V1 encoding and flips the CHOICE to GENERALNAMES_CID, | |
136 | * if the value is non-null, | |
137 | * and leaves unchanged if the value is set to null. | |
138 | * | |
139 | * @param v1 - the GeneralNames of the issuer; can be null | |
140 | */ | |
141 | 20 | public void setV1Form(GeneralNames v1){ |
142 | 20 | v1Form=v1; |
143 | 0 | if (v1!=null) setChoice(V1FORM_CID); |
144 | } | |
145 | ||
146 | ||
147 | protected V2Form v2Form = null; | |
148 | ||
149 | /** | |
150 | * Returns the value for V2 encoding (V2Form choice). | |
151 | */ | |
152 | 1068 | public V2Form getV2Form(){ |
153 | 1068 | return v2Form; |
154 | } | |
155 | ||
156 | /** | |
157 | * Sets the value for V2 encoding and flips the CHOICE to V2FORM_CID, if the | |
158 | * value is non-null, | |
159 | * and leaves unchanged if the value is set to null. | |
160 | * | |
161 | * @param v2 - the V2Form of the issuer; can be null | |
162 | */ | |
163 | 20 | public void setV2Form(V2Form v2){ |
164 | 20 | v2Form=v2; |
165 | 20 | if (v2!=null) setChoice(V2FORM_CID); |
166 | } | |
167 | ||
168 | 5998 | protected AttCertIssuer() { |
169 | } | |
170 | ||
171 | /** | |
172 | * This constructor builds AttCertIssuer from ASN1Object. | |
173 | * | |
174 | * @param ao - the ASN1Object of AttCertIssuer construct | |
175 | */ | |
176 | 2979 | public AttCertIssuer(ASN1Object ao) throws CodingException{ |
177 | 2979 | decode(ao); |
178 | } | |
179 | ||
180 | /** | |
181 | * This constructor copies AttCertIssuer. | |
182 | * | |
183 | * @param aci - the AttCertIssuer to be copied | |
184 | */ | |
185 | 0 | public AttCertIssuer(AttCertIssuer aci) throws CodingException{ |
186 | 0 | CHOICE = aci.CHOICE; |
187 | ||
188 | 0 | v1Form=null; |
189 | 0 | v2Form=null; |
190 | ||
191 | 0 | if (aci.v1Form!=null){ |
192 | // copy v1Form if V2Form is empty, and CHOICE ID is set to default | |
193 | 0 | v1Form = new GeneralNames(aci.v1Form.toASN1Object()); |
194 | } | |
195 | ||
196 | 0 | if (aci.v2Form!=null){ |
197 | 0 | v2Form = new V2Form(aci.v2Form); |
198 | } | |
199 | } | |
200 | ||
201 | /** | |
202 | * This constructor builds an object with the V1Form (GeneralNames) or V2Form | |
203 | * specified. You can | |
204 | * specify both of them, and manually flip the CHOICE variable value when you | |
205 | * can decide what | |
206 | * form of the certificate issuer information you need, so the object would | |
207 | * deliver | |
208 | * a definite result when encoding. If you don't do that, the V1Form will be | |
209 | * used by default, if both values are non-null. | |
210 | * | |
211 | * @param v1Form is the GeneralNames of the issuer | |
212 | * @param v2Form is the V2Form construct, containing the issuer information | |
213 | */ | |
214 | 20 | public AttCertIssuer(GeneralNames v1Form, V2Form v2Form){ |
215 | 20 | setV2Form(v2Form); |
216 | 20 | setV1Form(v1Form); // this makes sure V1Form takes precedence over V2Form |
217 | } | |
218 | ||
219 | /** | |
220 | * This method returns the ASN1Object of AttCertIssuer construct. The actual | |
221 | * value depends on the choice set: if it is GENERALNAMES_CID or | |
222 | * V1FORM_CID, a GeneralNames is the result; if it is V2FORM_CID, a V2Form | |
223 | * is output and is tagged with [0]; otherwise a CodingException occurs. | |
224 | * | |
225 | * <p>Whether the tagging is explicit or implicit, depends on | |
226 | * AttributeCertificate.USE_IMPLICIT_ENCODING. | |
227 | * | |
228 | * @return ASN1Object of AttCertIssuer | |
229 | * | |
230 | * @see AttributeCertificate#USE_IMPLICIT_ENCODING | |
231 | */ | |
232 | 42 | public ASN1Object toASN1Object() throws CodingException{ |
233 | 42 | ASN1Object result; |
234 | ||
235 | 42 | if ((CHOICE==GENERALNAMES_CID && v1Form==null) || |
236 | (CHOICE==V2FORM_CID && v2Form==null)){ | |
237 | 0 | throw new CodingException("AttCertIssuer misses both of the values: v1Form and v2Form"); |
238 | } | |
239 | ||
240 | 42 | if (CHOICE!=GENERALNAMES_CID && CHOICE!=V2FORM_CID){ |
241 | 0 | throw new CodingException("Internal error: CHOICE is not set"); |
242 | } | |
243 | ||
244 | 42 | if (CHOICE==GENERALNAMES_CID){ |
245 | 0 | result = v1Form.toASN1Object(); |
246 | }else{ | |
247 | 42 | result = new CON_SPEC(V2FORM_TAG, v2Form.toASN1Object(), AttributeCertificate.USE_IMPLICIT_ENCODING); |
248 | } | |
249 | 42 | return result; |
250 | } | |
251 | ||
252 | /** | |
253 | * This method decodes a given ASN1Object and sets the AttCertIssuer from | |
254 | * the content of that object. The content depends on whether the ASN1Object | |
255 | * has a context-specific tag [0]: if so, V2Form is expected; otherwise | |
256 | * V1Form is expected (GeneralNames). | |
257 | * | |
258 | * @param ao - the ASN1Object of AttCertIssuer | |
259 | */ | |
260 | 2979 | public void decode(ASN1Object ao) throws CodingException{ |
261 | 2979 | ASN type = ao.getAsnType(); |
262 | 2979 | if (type.getTagClass()==ASN.CONTEXT_SPECIFIC && type.getTag()==V2FORM_TAG){ |
263 | 2240 | CHOICE=V2FORM_CID; |
264 | ||
265 | 2240 | if (AttributeCertificate.USE_IMPLICIT_ENCODING){ |
266 | 1120 | ((CON_SPEC)ao).forceImplicitlyTagged(ASN.SEQUENCE); |
267 | } | |
268 | ||
269 | 2240 | if (ao.countComponents()!=1){ |
270 | 538 | throw new CodingException("Illegal number of entries in AttCertIssuer.v2Form tag: "+Integer.toString(ao.countComponents())); |
271 | } | |
272 | 1702 | v2Form = new V2Form(ao.getComponentAt(0)); |
273 | }else{ | |
274 | 739 | CHOICE=GENERALNAMES_CID; |
275 | 739 | v1Form = new GeneralNames(ao); |
276 | } | |
277 | } | |
278 | ||
279 | ||
280 | 0 | public String toString(){ |
281 | 0 | return toString(""); |
282 | } | |
283 | ||
284 | 4 | public String toString(String ident){ |
285 | 4 | return "CHOICE { -- AttCertIssuer --\n "+ident+ |
286 | 4 | ((CHOICE==GENERALNAMES_CID || v2Form==null)? "v1Form = "+v1Form.toString() : "v2Form = "+v2Form.toString())+ |
287 | "\n"+ident+"}"; | |
288 | } | |
289 | ||
290 | ||
291 | 0 | public Object clone(){ |
292 | 0 | try{ |
293 | 0 | return new AttCertIssuer(this); |
294 | }catch (CodingException ex){ | |
295 | 0 | ex.printStackTrace(); |
296 | 0 | return null; |
297 | } | |
298 | } | |
299 | ||
300 | } |
|