BasicAttConstraint | Line # 62 | 21 | 4 | 62.5% |
0.625
|
(1) | |||
Result | |||
0.575
|
issrg.test.ds.TestDS.testIssuing issrg.test.ds.TestDS.testIssuing | 1 PASS | |
1 | /* | |
2 | * Copyright (c) 2006, University of Kent | |
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 | * 1. Neither the name of the University of Kent 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 | * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. | |
23 | * | |
24 | * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
31 | * POSSIBILITY OF SUCH DAMAGE. | |
32 | * | |
33 | * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE | |
34 | * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS | |
35 | * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS | |
36 | * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH | |
37 | * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH | |
38 | * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY | |
39 | * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE | |
40 | * SERIOUS FAULTS, IN THIS SOFTWARE. | |
41 | * | |
42 | * 5. This license is governed, except to the extent that local laws | |
43 | * necessarily apply, by the laws of England and Wales. | |
44 | */ | |
45 | ||
46 | /* | |
47 | * BasicAttConstraint.java | |
48 | * | |
49 | * Created on March 23, 2005, 11:20 AM | |
50 | */ | |
51 | ||
52 | package issrg.ac.attributes; | |
53 | ||
54 | import iaik.asn1.*; | |
55 | ||
56 | import java.math.BigInteger; | |
57 | ||
58 | /** | |
59 | * | |
60 | * @author anhnt | |
61 | */ | |
62 | public class BasicAttConstraint extends issrg.ac.Extension { | |
63 | ||
64 | /** | |
65 | *The string stores the standard OID for the basicAttConstraints: 2.5.29.41 | |
66 | */ | |
67 | public static final String BASIC_ATT_CONSTRAINT_OID = "2.5.29.41"; | |
68 | ||
69 | private int depth; | |
70 | ||
71 | /** | |
72 | * This method registers this extension as an extension with a specific | |
73 | * OID. After it has been registered, Extensions can recognise | |
74 | * the extension with this OID. | |
75 | */ | |
76 | ||
77 | 19 | public static void registerMe() { |
78 | 19 | issrg.ac.Extensions.registerExtension(BASIC_ATT_CONSTRAINT_OID, BasicAttConstraint.class); |
79 | } | |
80 | ||
81 | ||
82 | /** | |
83 | *Constructor for the class from an existing basicAttConstraints object | |
84 | *@param e is a basicAttConstraint object | |
85 | */ | |
86 | ||
87 | 0 | public BasicAttConstraint(BasicAttConstraint e) throws CodingException { |
88 | 0 | super(BASIC_ATT_CONSTRAINT_OID, e.isCritical()); |
89 | 0 | setDepth(e.getDepth()); |
90 | } | |
91 | ||
92 | /** | |
93 | * This constructor builds a BasicAttributeConstraint extension with no limit on Delegation depth. | |
94 | * This is the same as calling BasicAttConstraint(critical, null). | |
95 | *@param critical is a boolean value that specifies the critical of the object | |
96 | */ | |
97 | 0 | public BasicAttConstraint (boolean critical) { |
98 | 0 | this(critical, -1); //unlimited delegation depth |
99 | } | |
100 | ||
101 | /** | |
102 | * This constructor builds a BasicAttributeConstraint extension with the specified limit on Delegation depth. | |
103 | * If delegation depth is null or is a negative number, an unlimited delegation is assumed. | |
104 | * | |
105 | * @param critical - the criticality flag; if true, the extension is marked critical | |
106 | * @param depth - the depth of delegation; if null or negative, no delegation limit is assumed. | |
107 | */ | |
108 | 16 | public BasicAttConstraint (boolean critical, int depth) { |
109 | 16 | super(BASIC_ATT_CONSTRAINT_OID, critical); |
110 | 16 | setDepth(depth); |
111 | } | |
112 | ||
113 | /** | |
114 | *This method returns the delegation depth of the basicAttConstraints object | |
115 | *@return an integer that represents the delegation depth of the object | |
116 | */ | |
117 | ||
118 | 918 | public int getDepth(){ |
119 | 918 | return depth; |
120 | } | |
121 | ||
122 | /** | |
123 | *This method set the delegation depth for the object | |
124 | *@param d is an integer. Is is used for setting the delegation depth for the object | |
125 | */ | |
126 | 919 | public void setDepth(int d){ |
127 | 919 | depth=d; |
128 | } | |
129 | ||
130 | /** | |
131 | *This method encodes the extension value of this extension | |
132 | *to an ASN1Object. | |
133 | * | |
134 | *@return an ASN1Object | |
135 | */ | |
136 | 32 | public ASN1Object encodeValue() throws CodingException{ |
137 | 32 | ASN1Object extnValue = new SEQUENCE(); |
138 | 32 | extnValue.addComponent(new BOOLEAN(true)); |
139 | 32 | if (getDepth()>=0) { |
140 | 16 | extnValue.addComponent(new INTEGER(getDepth())); |
141 | } | |
142 | ||
143 | 32 | return extnValue; |
144 | } | |
145 | ||
146 | 0 | public Object clone(){ |
147 | 0 | try { |
148 | 0 | return new BasicAttConstraint(this); |
149 | 0 | } catch (CodingException ce) {return null;} |
150 | } | |
151 | ||
152 | /** | |
153 | * This method constructs an BasicAttConstraints object from an | |
154 | *ASN1Object. | |
155 | * | |
156 | *@param ao is an ASN1Object. | |
157 | */ | |
158 | ||
159 | 903 | public BasicAttConstraint(ASN1Object ao) throws CodingException{ |
160 | 903 | super(ao); |
161 | } | |
162 | ||
163 | /** | |
164 | *This method decodes an ASN1Object to get an extension value | |
165 | *for the BasicAttConstraint object. | |
166 | * | |
167 | *@param ao is the ASN1Object. | |
168 | */ | |
169 | ||
170 | 903 | public void decodeValue(ASN1Object ao) throws CodingException{ |
171 | 903 | if (!(ao.getComponentAt(0) instanceof BOOLEAN)){ |
172 | 0 | throw new CodingException("Invalid format of BasicAttConstraint extension: BOOLEAN was expected"); |
173 | } | |
174 | ||
175 | 903 | setDepth((ao.countComponents()==2)?((BigInteger)((INTEGER) ao.getComponentAt(1)).getValue()).intValue():-1); |
176 | } | |
177 | ||
178 | /** | |
179 | *This method returns a string that represents the object | |
180 | *@param ident is a string that used for seperating the critical value and the delegation depth of the object | |
181 | */ | |
182 | 0 | public String extensionValueToString(String ident){ |
183 | 0 | return "TRUE, "+(getDepth()<0?"(unlimited)":(""+getDepth())); |
184 | } | |
185 | } |
|