104 int quoteCount = 0;
105 int searchOffset = 0;
106 int avaOffset = 0;
107 List<AVA> avaVec = new ArrayList<>(3);
108 int nextPlus = name.indexOf('+');
109 while (nextPlus >= 0) {
110 quoteCount += X500Name.countQuotes(name, searchOffset, nextPlus);
111 /*
112 * We have encountered an AVA delimiter (plus sign).
113 * If the plus sign in the RDN under consideration is
114 * preceded by a backslash (escape), or by a double quote, it
115 * is part of the AVA. Otherwise, it is used as a separator, to
116 * delimit the AVA under consideration from any subsequent AVAs.
117 */
118 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\'
119 && quoteCount != 1) {
120 /*
121 * Plus sign is a separator
122 */
123 String avaString = name.substring(avaOffset, nextPlus);
124 if (avaString.length() == 0) {
125 throw new IOException("empty AVA in RDN \"" + name + "\"");
126 }
127
128 // Parse AVA, and store it in vector
129 AVA ava = new AVA(new StringReader(avaString), keywordMap);
130 avaVec.add(ava);
131
132 // Increase the offset
133 avaOffset = nextPlus + 1;
134
135 // Set quote counter back to zero
136 quoteCount = 0;
137 }
138 searchOffset = nextPlus + 1;
139 nextPlus = name.indexOf('+', searchOffset);
140 }
141
142 // parse last or only AVA
143 String avaString = name.substring(avaOffset);
144 if (avaString.length() == 0) {
145 throw new IOException("empty AVA in RDN \"" + name + "\"");
146 }
147 AVA ava = new AVA(new StringReader(avaString), keywordMap);
148 avaVec.add(ava);
149
150 assertion = avaVec.toArray(new AVA[avaVec.size()]);
151 }
152
153 /*
154 * Constructs an RDN from its printable representation.
155 *
156 * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
157 * using '+' as a separator.
158 * If the '+' should be considered part of an AVA value, it must be
159 * preceded by '\'.
160 *
161 * @param name String form of RDN
162 * @throws IOException on parsing error
163 */
164 RDN(String name, String format) throws IOException {
182 if (format.equalsIgnoreCase("RFC2253") == false) {
183 throw new IOException("Unsupported format " + format);
184 }
185 int searchOffset = 0;
186 int avaOffset = 0;
187 List<AVA> avaVec = new ArrayList<>(3);
188 int nextPlus = name.indexOf('+');
189 while (nextPlus >= 0) {
190 /*
191 * We have encountered an AVA delimiter (plus sign).
192 * If the plus sign in the RDN under consideration is
193 * preceded by a backslash (escape), or by a double quote, it
194 * is part of the AVA. Otherwise, it is used as a separator, to
195 * delimit the AVA under consideration from any subsequent AVAs.
196 */
197 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\' ) {
198 /*
199 * Plus sign is a separator
200 */
201 String avaString = name.substring(avaOffset, nextPlus);
202 if (avaString.length() == 0) {
203 throw new IOException("empty AVA in RDN \"" + name + "\"");
204 }
205
206 // Parse AVA, and store it in vector
207 AVA ava = new AVA
208 (new StringReader(avaString), AVA.RFC2253, keywordMap);
209 avaVec.add(ava);
210
211 // Increase the offset
212 avaOffset = nextPlus + 1;
213 }
214 searchOffset = nextPlus + 1;
215 nextPlus = name.indexOf('+', searchOffset);
216 }
217
218 // parse last or only AVA
219 String avaString = name.substring(avaOffset);
220 if (avaString.length() == 0) {
221 throw new IOException("empty AVA in RDN \"" + name + "\"");
222 }
223 AVA ava = new AVA(new StringReader(avaString), AVA.RFC2253, keywordMap);
224 avaVec.add(ava);
225
226 assertion = avaVec.toArray(new AVA[avaVec.size()]);
227 }
228
229 /*
230 * Constructs an RDN from an ASN.1 encoded value. The encoding
231 * of the name in the stream uses DER (a BER/1 subset).
232 *
233 * @param value a DER-encoded value holding an RDN.
234 * @throws IOException on parsing error.
235 */
236 RDN(DerValue rdn) throws IOException {
237 if (rdn.tag != DerValue.tag_Set) {
238 throw new IOException("X500 RDN");
239 }
240 DerInputStream dis = new DerInputStream(rdn.toByteArray());
|
104 int quoteCount = 0;
105 int searchOffset = 0;
106 int avaOffset = 0;
107 List<AVA> avaVec = new ArrayList<>(3);
108 int nextPlus = name.indexOf('+');
109 while (nextPlus >= 0) {
110 quoteCount += X500Name.countQuotes(name, searchOffset, nextPlus);
111 /*
112 * We have encountered an AVA delimiter (plus sign).
113 * If the plus sign in the RDN under consideration is
114 * preceded by a backslash (escape), or by a double quote, it
115 * is part of the AVA. Otherwise, it is used as a separator, to
116 * delimit the AVA under consideration from any subsequent AVAs.
117 */
118 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\'
119 && quoteCount != 1) {
120 /*
121 * Plus sign is a separator
122 */
123 String avaString = name.substring(avaOffset, nextPlus);
124 if (avaString.isEmpty()) {
125 throw new IOException("empty AVA in RDN \"" + name + "\"");
126 }
127
128 // Parse AVA, and store it in vector
129 AVA ava = new AVA(new StringReader(avaString), keywordMap);
130 avaVec.add(ava);
131
132 // Increase the offset
133 avaOffset = nextPlus + 1;
134
135 // Set quote counter back to zero
136 quoteCount = 0;
137 }
138 searchOffset = nextPlus + 1;
139 nextPlus = name.indexOf('+', searchOffset);
140 }
141
142 // parse last or only AVA
143 String avaString = name.substring(avaOffset);
144 if (avaString.isEmpty()) {
145 throw new IOException("empty AVA in RDN \"" + name + "\"");
146 }
147 AVA ava = new AVA(new StringReader(avaString), keywordMap);
148 avaVec.add(ava);
149
150 assertion = avaVec.toArray(new AVA[avaVec.size()]);
151 }
152
153 /*
154 * Constructs an RDN from its printable representation.
155 *
156 * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
157 * using '+' as a separator.
158 * If the '+' should be considered part of an AVA value, it must be
159 * preceded by '\'.
160 *
161 * @param name String form of RDN
162 * @throws IOException on parsing error
163 */
164 RDN(String name, String format) throws IOException {
182 if (format.equalsIgnoreCase("RFC2253") == false) {
183 throw new IOException("Unsupported format " + format);
184 }
185 int searchOffset = 0;
186 int avaOffset = 0;
187 List<AVA> avaVec = new ArrayList<>(3);
188 int nextPlus = name.indexOf('+');
189 while (nextPlus >= 0) {
190 /*
191 * We have encountered an AVA delimiter (plus sign).
192 * If the plus sign in the RDN under consideration is
193 * preceded by a backslash (escape), or by a double quote, it
194 * is part of the AVA. Otherwise, it is used as a separator, to
195 * delimit the AVA under consideration from any subsequent AVAs.
196 */
197 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\' ) {
198 /*
199 * Plus sign is a separator
200 */
201 String avaString = name.substring(avaOffset, nextPlus);
202 if (avaString.isEmpty()) {
203 throw new IOException("empty AVA in RDN \"" + name + "\"");
204 }
205
206 // Parse AVA, and store it in vector
207 AVA ava = new AVA
208 (new StringReader(avaString), AVA.RFC2253, keywordMap);
209 avaVec.add(ava);
210
211 // Increase the offset
212 avaOffset = nextPlus + 1;
213 }
214 searchOffset = nextPlus + 1;
215 nextPlus = name.indexOf('+', searchOffset);
216 }
217
218 // parse last or only AVA
219 String avaString = name.substring(avaOffset);
220 if (avaString.isEmpty()) {
221 throw new IOException("empty AVA in RDN \"" + name + "\"");
222 }
223 AVA ava = new AVA(new StringReader(avaString), AVA.RFC2253, keywordMap);
224 avaVec.add(ava);
225
226 assertion = avaVec.toArray(new AVA[avaVec.size()]);
227 }
228
229 /*
230 * Constructs an RDN from an ASN.1 encoded value. The encoding
231 * of the name in the stream uses DER (a BER/1 subset).
232 *
233 * @param value a DER-encoded value holding an RDN.
234 * @throws IOException on parsing error.
235 */
236 RDN(DerValue rdn) throws IOException {
237 if (rdn.tag != DerValue.tag_Set) {
238 throw new IOException("X500 RDN");
239 }
240 DerInputStream dis = new DerInputStream(rdn.toByteArray());
|