1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
package issrg.utils; |
77 |
|
|
78 |
|
import java.util.Vector; |
79 |
|
import java.text.StringCharacterIterator; |
80 |
|
import java.text.CharacterIterator; |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@author |
114 |
|
|
115 |
|
|
|
|
| 88% |
Uncovered Elements: 55 (457) |
Complexity: 97 |
Complexity Density: 0.46 |
|
116 |
|
public class RFC2253NameParser { |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
private final static char A_CHAR = 65; |
122 |
|
private final static char a_CHAR = 97; |
123 |
|
private final static char F_CHAR = 70; |
124 |
|
private final static char f_CHAR = 95; |
125 |
|
|
126 |
|
private final static char X_CHAR = 88; |
127 |
|
private final static char x_CHAR = 120; |
128 |
|
|
129 |
|
private final static char Z_CHAR = 90; |
130 |
|
private final static char z_CHAR = 122; |
131 |
|
|
132 |
|
private final static char NINE_CHAR = 57; |
133 |
|
private final static char ZERO_CHAR = 48; |
134 |
|
|
135 |
|
private final static char LT_CHAR = '<'; |
136 |
|
private final static char GT_CHAR = '>'; |
137 |
|
|
138 |
|
public final static char ASSIGN_CHAR = 61; |
139 |
|
public final static char COMMA_CHAR = 44; |
140 |
|
private final static char HYPHEN_CHAR = 45; |
141 |
|
public final static char PLUS_CHAR = 43; |
142 |
|
private final static char SEMICOLON_CHAR = 59; |
143 |
|
|
144 |
|
private final static char APOSTROPHE_CHAR = 39; |
145 |
|
private final static char BSLASH_CHAR = 92; |
146 |
|
private final static char HASH_CHAR = 35; |
147 |
|
private final static char SLASH_CHAR = 47; |
148 |
|
private final static char SPACE_CHAR = 32; |
149 |
|
private final static char QUOTE_CHAR = 34; |
150 |
|
|
151 |
|
private final static char DOT_CHAR = 46; |
152 |
|
private final static char O_CHAR = 79; |
153 |
|
private final static char I_CHAR = 73; |
154 |
|
private final static char D_CHAR = 68; |
155 |
|
private final static char o_CHAR = 111; |
156 |
|
private final static char i_CHAR = 105; |
157 |
|
private final static char d_CHAR = 100; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@param |
164 |
|
@return |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@link |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@throws |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
|
|
| 86.7% |
Uncovered Elements: 4 (30) |
Complexity: 7 |
Complexity Density: 0.35 |
|
185 |
12854
|
public static String [][][] distinguishedName(String Name) throws RFC2253ParsingException{... |
186 |
12854
|
if (Name==null){ |
187 |
0
|
throw new IllegalArgumentException("Name parameter cannot be null"); |
188 |
|
} |
189 |
|
|
190 |
12854
|
Name=Name.trim(); |
191 |
|
|
192 |
12854
|
if (Name.intern()==""){ |
193 |
46
|
return new String[0][][]; |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
12808
|
CharacterIterator ci = new StringCharacterIterator(Name); |
203 |
|
|
204 |
12808
|
if (Name.startsWith(new String(new char[]{SLASH_CHAR, DOT_CHAR, DOT_CHAR, DOT_CHAR, SLASH_CHAR}))){ |
205 |
1
|
ci.setIndex(4); |
206 |
|
} |
207 |
|
|
208 |
12808
|
try{ |
209 |
12808
|
String [][][] dn = name(ci, Name.startsWith(new String(new char[]{SLASH_CHAR}))); |
210 |
|
|
211 |
12800
|
if (ci.getIndex()<ci.getEndIndex()){ |
212 |
2
|
throw new RFC2253ParsingException("End of Distinguished Name expected."); |
213 |
|
} |
214 |
12798
|
return dn; |
215 |
|
}catch(Exception ex){ |
216 |
10
|
String msg = null; |
217 |
10
|
int pos = 0; |
218 |
|
|
219 |
10
|
if (ci==null){ |
220 |
0
|
msg = "CharacterIterator is null"; |
221 |
|
}else{ |
222 |
10
|
pos = ci.getIndex(); |
223 |
10
|
msg = "Parse error at "+(pos); |
224 |
|
} |
225 |
10
|
throw new RFC2253ParsingException(pos, msg, ex); |
226 |
|
} |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
@param |
290 |
|
|
291 |
|
@return |
292 |
|
|
293 |
|
@throws |
294 |
|
|
295 |
|
|
296 |
|
|
|
|
| 84% |
Uncovered Elements: 4 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
297 |
12821
|
public static String toCanonicalDN(String [][][] dn){... |
298 |
12821
|
StringBuffer sb = new StringBuffer(); |
299 |
|
|
300 |
65279
|
for (int i=0; i<dn.length; i++){ |
301 |
52458
|
if (i!=0){ |
302 |
39683
|
sb.append(COMMA_CHAR); |
303 |
|
} |
304 |
|
|
305 |
104916
|
for (int j=0; j<dn[i].length; j++){ |
306 |
52458
|
if (j!=0){ |
307 |
0
|
sb.append(PLUS_CHAR); |
308 |
|
} |
309 |
|
|
310 |
52458
|
sb.append(dn[i][j][0].toUpperCase()); |
311 |
52458
|
sb.append(ASSIGN_CHAR); |
312 |
|
|
313 |
52458
|
String t; |
314 |
52458
|
if (dn[i][j].length>2 && dn[i][j][2]!=null){ |
315 |
0
|
t=dn[i][j][2]; |
316 |
|
}else{ |
317 |
52458
|
t=escapeString(dn[i][j][1]); |
318 |
|
} |
319 |
|
|
320 |
52458
|
sb.append(t); |
321 |
|
} |
322 |
|
} |
323 |
|
|
324 |
12821
|
return sb.toString(); |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
@param |
335 |
|
|
336 |
|
@return |
337 |
|
|
338 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
339 |
70
|
public static String toCanonicalDN(String dn){... |
340 |
70
|
String canonical = null; |
341 |
70
|
try{ |
342 |
70
|
if (dn!=null) canonical = toCanonicalDN(distinguishedName(dn)); |
343 |
|
}catch(RFC2253ParsingException rpe){ |
344 |
|
} |
345 |
|
|
346 |
70
|
return canonical; |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
@param |
353 |
|
|
354 |
|
@param |
355 |
|
|
356 |
|
|
357 |
|
@return |
358 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 8 |
Complexity Density: 0.57 |
|
359 |
12808
|
protected static String [][][] name(CharacterIterator n, boolean OSF) throws RFC2253ParsingException{... |
360 |
12808
|
Vector result = new Vector(); |
361 |
|
|
362 |
12808
|
while (true){ |
363 |
52503
|
result.add(name_component(n, OSF)); |
364 |
52495
|
skip_spaces(n); |
365 |
|
|
366 |
52495
|
if ((!OSF && !COMMA(n.current())) || (OSF && !SLASH(n.current()))) { |
367 |
12800
|
break; |
368 |
|
} |
369 |
|
|
370 |
39695
|
if (!OSF) { |
371 |
39690
|
n.next(); |
372 |
39690
|
skip_spaces(n); |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
12800
|
Object [] o = result.toArray(); |
377 |
12800
|
String [][][] s = new String[o.length][][]; |
378 |
65293
|
for (int i=0; i<s.length; i++){ |
379 |
52493
|
s[OSF?s.length-1-i:i] = (String [][])o[i]; |
380 |
|
} |
381 |
|
|
382 |
12800
|
return s; |
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
@param |
389 |
|
|
390 |
|
@param |
391 |
|
|
392 |
|
|
393 |
|
@return |
394 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 8 |
Complexity Density: 0.5 |
|
395 |
52503
|
protected static String [][] name_component(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
396 |
52503
|
if (OSF) { |
397 |
10
|
ci.next(); |
398 |
10
|
skip_spaces(ci); |
399 |
|
} |
400 |
|
|
401 |
52503
|
Vector result = new Vector(); |
402 |
|
|
403 |
52503
|
while(true){ |
404 |
52506
|
result.add(attributeTypeAndValue(ci, OSF)); |
405 |
52498
|
skip_spaces(ci); |
406 |
|
|
407 |
52498
|
if ((!OSF && !PLUS(ci.current())) || (OSF && !COMMA(ci.current()))) |
408 |
52495
|
break; |
409 |
|
|
410 |
3
|
ci.next(); |
411 |
|
|
412 |
3
|
skip_spaces(ci); |
413 |
|
} |
414 |
|
|
415 |
52495
|
Object [] o = result.toArray(); |
416 |
52495
|
String [][] s = new String[o.length][]; |
417 |
104993
|
for (int i=0; i<s.length; i++){ |
418 |
52498
|
s[i] = (String [])o[i]; |
419 |
|
} |
420 |
|
|
421 |
52495
|
return s; |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
@param |
428 |
|
|
429 |
|
@param |
430 |
|
|
431 |
|
|
432 |
|
@return |
433 |
|
|
434 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
435 |
52506
|
protected static String [] attributeTypeAndValue(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
436 |
52506
|
String [] pair = new String[2]; |
437 |
|
|
438 |
52506
|
pair[0] = attributeType(ci, OSF); |
439 |
|
|
440 |
52506
|
skip_spaces(ci); |
441 |
|
|
442 |
52506
|
if (!ASSIGNMENT(ci.current()) || pair[0]==null){ |
443 |
6
|
if (!OSF) throw new RFC2253ParsingException("Assignment mark ('"+ASSIGN_CHAR+"') expected"); |
444 |
|
} else { |
445 |
52500
|
ci.next(); |
446 |
52500
|
skip_spaces(ci); |
447 |
|
} |
448 |
|
|
449 |
52501
|
pair[1] = attributeValue(ci, OSF); |
450 |
52498
|
if ( pair[1].startsWith("#") ){ |
451 |
2
|
pair = new String[] { pair[0], null, pair[1] }; |
452 |
|
} |
453 |
|
|
454 |
52498
|
return pair; |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
@param |
465 |
|
|
466 |
|
@param |
467 |
|
|
468 |
|
|
469 |
|
@return |
470 |
|
|
|
|
| 62.5% |
Uncovered Elements: 9 (24) |
Complexity: 7 |
Complexity Density: 0.44 |
|
471 |
52506
|
protected static String attributeType(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
472 |
52506
|
StringBuffer result = new StringBuffer(); |
473 |
|
|
474 |
52506
|
int currentPos = ci.getIndex(); |
475 |
|
|
476 |
52506
|
try{ |
477 |
52506
|
result.append(oid(ci)); |
478 |
|
}catch(RFC2253ParsingException ex){ |
479 |
52501
|
ci.setIndex(currentPos); |
480 |
|
|
481 |
52501
|
char c; |
482 |
0
|
if (ALPHA(c=ci.current())){ |
483 |
52501
|
do{ |
484 |
86669
|
result.append(c); |
485 |
0
|
}while(keychar(c=ci.next())); |
486 |
|
|
487 |
52501
|
if (OSF && !ASSIGNMENT(c)) { |
488 |
1
|
ci.setIndex(currentPos); |
489 |
|
|
490 |
1
|
return null; |
491 |
|
} |
492 |
|
}else{ |
493 |
0
|
if (OSF) return null; |
494 |
0
|
throw new RFC2253ParsingException("attributeType expected"); |
495 |
|
} |
496 |
|
} |
497 |
|
|
498 |
52505
|
return result.toString(); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
|
506 |
|
@param |
507 |
|
|
508 |
|
@return |
509 |
|
|
510 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
511 |
86669
|
protected static boolean keychar(char c){... |
512 |
86669
|
return c==HYPHEN_CHAR || ALPHA(c) || DIGIT(c); |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
@param |
520 |
|
|
521 |
|
|
522 |
|
@return |
523 |
|
|
|
|
| 95.8% |
Uncovered Elements: 2 (48) |
Complexity: 12 |
Complexity Density: 0.46 |
|
524 |
52506
|
protected static String oid(CharacterIterator ci) throws RFC2253ParsingException{... |
525 |
52506
|
char [] OID_string = {O_CHAR, I_CHAR, D_CHAR, DOT_CHAR}; |
526 |
52506
|
char [] oid_string = {o_CHAR, i_CHAR, d_CHAR, DOT_CHAR}; |
527 |
52506
|
char c; |
528 |
52506
|
illegal_oid: |
529 |
|
do{ |
530 |
|
|
531 |
|
|
532 |
|
|
533 |
52506
|
c=ci.current(); |
534 |
|
|
535 |
52506
|
if (c==oid_string[0]){ |
536 |
12473
|
for (int i=0; i<oid_string.length; i++, ci.next()){ |
537 |
12468
|
if (ci.current()!=oid_string[i]){ |
538 |
6224
|
break illegal_oid; |
539 |
|
} |
540 |
|
} |
541 |
|
}else{ |
542 |
46277
|
if (c==OID_string[0]){ |
543 |
40953
|
for (int i=0; i<OID_string.length; i++, ci.next()){ |
544 |
40952
|
if (ci.current()!=OID_string[i]){ |
545 |
20474
|
break illegal_oid; |
546 |
|
} |
547 |
|
} |
548 |
|
} |
549 |
|
} |
550 |
|
|
551 |
25808
|
StringBuffer result = new StringBuffer(); |
552 |
25808
|
if (!DIGIT(ci.current())) break illegal_oid; |
553 |
|
|
554 |
6
|
do{ result.append(ci.current()); }while(DIGIT(ci.next())); |
555 |
|
|
556 |
14
|
while(ci.current()==DOT_CHAR){ |
557 |
9
|
result.append(ci.current()); |
558 |
|
|
559 |
9
|
if (!DIGIT(ci.next())) break illegal_oid; |
560 |
8
|
do{ result.append(ci.current()); }while(DIGIT(ci.next())); |
561 |
|
} |
562 |
|
|
563 |
5
|
return result.toString(); |
564 |
|
|
565 |
|
}while(false); |
566 |
|
|
567 |
52501
|
throw new RFC2253ParsingException("Valid OID specification expected"); |
568 |
|
} |
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
@param |
575 |
|
|
576 |
|
@param |
577 |
|
|
578 |
|
|
579 |
|
@return |
580 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
581 |
52501
|
protected static String attributeValue(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
582 |
52501
|
skip_spaces(ci); |
583 |
|
|
584 |
52501
|
String s = string(ci, OSF); |
585 |
|
|
586 |
52498
|
skip_spaces(ci); |
587 |
|
|
588 |
52498
|
return s; |
589 |
|
|
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
@param |
599 |
|
|
600 |
|
@param |
601 |
|
|
602 |
|
|
603 |
|
@return |
604 |
|
|
|
|
| 95.2% |
Uncovered Elements: 3 (63) |
Complexity: 15 |
Complexity Density: 0.37 |
|
605 |
52501
|
protected static String string(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
606 |
52501
|
StringBuffer result = new StringBuffer(); |
607 |
|
|
608 |
52501
|
char c = ci.current(); |
609 |
52501
|
if (c==HASH_CHAR && !OSF){ |
610 |
2
|
ci.next(); |
611 |
|
|
612 |
2
|
return hexstring(ci); |
613 |
|
|
614 |
|
}else{ |
615 |
52499
|
if (QUOTATION(c, OSF)){ |
616 |
9
|
ci.next(); |
617 |
|
|
618 |
9
|
try{ |
619 |
0
|
while(!QUOTATION(c=ci.current(), OSF)){ |
620 |
30
|
if (quotechar(c, OSF)){ |
621 |
23
|
result.append(c); |
622 |
23
|
ci.next(); |
623 |
|
}else{ |
624 |
7
|
result.append(pair(ci, OSF)); |
625 |
|
} |
626 |
|
} |
627 |
|
}catch(RFC2253ParsingException ex){ |
628 |
3
|
throw new RFC2253ParsingException("Quotation character (["+(OSF?APOSTROPHE_CHAR:QUOTE_CHAR)+"]) expected", ex); |
629 |
|
} |
630 |
|
|
631 |
6
|
ci.next(); |
632 |
|
}else{ |
633 |
52490
|
int spaces = -1; |
634 |
52490
|
int currentPos=0; |
635 |
52490
|
try{ |
636 |
52489
|
do{ |
637 |
431669
|
c = ci.current(); |
638 |
|
|
639 |
431670
|
if (c==SPACE_CHAR){ |
640 |
14228
|
if (spaces<0) spaces=ci.getIndex(); |
641 |
14228
|
ci.next(); |
642 |
14228
|
continue; |
643 |
|
} |
644 |
|
|
645 |
|
|
646 |
417442
|
currentPos = ci.getIndex(); |
647 |
|
|
648 |
417442
|
if (stringchar(c, OSF)){ |
649 |
364942
|
ci.next(); |
650 |
|
}else{ |
651 |
52500
|
c = pair(ci, OSF); |
652 |
|
} |
653 |
|
|
654 |
364951
|
if (spaces>-1){ |
655 |
14109
|
int remember = ci.getIndex(); |
656 |
|
|
657 |
14109
|
ci.setIndex(spaces); |
658 |
14109
|
spaces=-1; |
659 |
|
|
660 |
|
|
661 |
28218
|
while(ci.getIndex()<currentPos){ |
662 |
14109
|
result.append(ci.current()); |
663 |
14109
|
ci.next(); |
664 |
|
} |
665 |
|
|
666 |
14109
|
ci.setIndex(remember); |
667 |
|
} |
668 |
|
|
669 |
364951
|
result.append(c); |
670 |
|
|
671 |
|
}while(true); |
672 |
|
|
673 |
|
}catch(RFC2253ParsingException ex){ |
674 |
|
} |
675 |
|
|
676 |
52490
|
if (spaces>-1){ |
677 |
118
|
ci.setIndex(spaces); |
678 |
|
} |
679 |
|
} |
680 |
|
} |
681 |
|
|
682 |
52496
|
return result.toString(); |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
@param |
690 |
|
@param |
691 |
|
|
692 |
|
|
693 |
|
@return |
694 |
|
|
695 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
696 |
30
|
protected static boolean quotechar(char c, boolean OSF){... |
697 |
30
|
return c!=BSLASH_CHAR && !QUOTATION(c, OSF) && c!=CharacterIterator.DONE; |
698 |
|
} |
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
@param |
704 |
|
@param |
705 |
|
|
706 |
|
|
707 |
|
@return |
708 |
|
|
709 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 1 |
|
710 |
783994
|
protected static boolean special(char c, boolean OSF){... |
711 |
783994
|
return c!=CharacterIterator.DONE && ( |
712 |
783994
|
ASSIGNMENT(c) || (OSF? |
713 |
|
(SLASH(c) || COMMA(c)) |
714 |
|
:(COMMA(c) || PLUS(c) || |
715 |
|
c==LT_CHAR || c==GT_CHAR || c==HASH_CHAR)) |
716 |
|
); |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
|
@param |
728 |
|
|
729 |
|
|
730 |
|
@param |
731 |
|
|
732 |
|
|
733 |
|
@return |
734 |
|
|
735 |
|
@throws |
736 |
|
|
737 |
|
|
738 |
|
|
739 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
740 |
52507
|
protected static char pair(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
741 |
52507
|
int p = onePair( ci, OSF ); |
742 |
14
|
int i = 0x40; |
743 |
|
|
744 |
14
|
if (p > 0x7f) { |
745 |
7
|
p &= 0x7f; |
746 |
14
|
while( (p & i) != 0 ) |
747 |
|
{ |
748 |
7
|
p = ((p ^ i) << 6) | (onePair( ci, OSF ) & 0x3f); |
749 |
7
|
i <<= 5; |
750 |
|
} |
751 |
|
} |
752 |
|
|
753 |
14
|
return (char)p; |
754 |
|
} |
755 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 10 |
Complexity Density: 0.59 |
|
756 |
52514
|
protected static int onePair(CharacterIterator ci, boolean OSF) throws RFC2253ParsingException{... |
757 |
52514
|
int result; |
758 |
52514
|
int currentPos = ci.getIndex(); |
759 |
52514
|
char c; |
760 |
|
|
761 |
52514
|
try{ |
762 |
52514
|
if (ci.current()!=BSLASH_CHAR){ |
763 |
52492
|
throw new RFC2253ParsingException("Backslash ('"+BSLASH_CHAR+"') escape expected"); |
764 |
|
} |
765 |
|
|
766 |
22
|
result=c=ci.next(); |
767 |
22
|
if (OSF){ |
768 |
2
|
if (c==X_CHAR || c==x_CHAR){ |
769 |
1
|
ci.next(); |
770 |
1
|
result=Integer.parseInt( hexpair(ci), 16 ); |
771 |
|
} |
772 |
20
|
}else if (c==BSLASH_CHAR || special(c, OSF) || QUOTATION(c, OSF) |
773 |
|
|| c==SPACE_CHAR){ |
774 |
2
|
ci.next(); |
775 |
|
}else{ |
776 |
18
|
result=Integer.parseInt( hexpair(ci), 16 ); |
777 |
|
} |
778 |
|
|
779 |
21
|
return result; |
780 |
|
}catch(RFC2253ParsingException ex){ |
781 |
52493
|
ci.setIndex(currentPos); |
782 |
52493
|
throw ex; |
783 |
|
} |
784 |
|
} |
785 |
|
|
786 |
|
|
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
@param |
791 |
|
@param |
792 |
|
|
793 |
|
|
794 |
|
@return |
795 |
|
|
796 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
797 |
796768
|
protected static boolean stringchar(char c, boolean OSF){... |
798 |
796768
|
return c!=CharacterIterator.DONE && |
799 |
|
!special(c, OSF) && |
800 |
|
!QUOTATION(c, OSF) && |
801 |
|
c!=BSLASH_CHAR; |
802 |
|
} |
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
|
807 |
|
|
808 |
|
@param |
809 |
|
|
810 |
|
|
811 |
|
@return |
812 |
|
|
813 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.5 |
|
814 |
2
|
protected static String hexstring(CharacterIterator ci) throws RFC2253ParsingException{... |
815 |
2
|
StringBuffer result = new StringBuffer("#"); |
816 |
|
|
817 |
2
|
result.append(hexpair(ci)); |
818 |
2
|
try{ |
819 |
2
|
while(true){ |
820 |
5
|
result.append(hexpair(ci)); |
821 |
|
} |
822 |
|
}catch(RFC2253ParsingException ex){ |
823 |
|
} |
824 |
|
|
825 |
2
|
return result.toString(); |
826 |
|
} |
827 |
|
|
828 |
|
|
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
@param |
833 |
|
|
834 |
|
|
835 |
|
@throws |
836 |
|
|
837 |
|
|
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
838 |
26
|
protected static String hexpair(CharacterIterator ci) throws RFC2253ParsingException{... |
839 |
26
|
int currentPos = ci.getIndex(); |
840 |
|
|
841 |
26
|
char c; |
842 |
0
|
if (hexchar(c=ci.current())){ |
843 |
24
|
char c1; |
844 |
0
|
if (hexchar(c1=ci.next())){ |
845 |
23
|
ci.next(); |
846 |
23
|
return new String( new char[]{c, c1} ); |
847 |
|
} |
848 |
|
} |
849 |
|
|
850 |
3
|
ci.setIndex(currentPos); |
851 |
3
|
throw new RFC2253ParsingException("Valid hexadecimal 8-bit number expected"); |
852 |
|
} |
853 |
|
|
854 |
|
|
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
|
859 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
860 |
0
|
private static int unhex(char c){... |
861 |
0
|
if (c<A_CHAR){ |
862 |
0
|
return c-ZERO_CHAR; |
863 |
|
} |
864 |
|
|
865 |
0
|
if (c<a_CHAR){ |
866 |
0
|
return c-A_CHAR+10; |
867 |
|
} |
868 |
|
|
869 |
0
|
return c-a_CHAR+10; |
870 |
|
} |
871 |
|
|
872 |
|
|
873 |
|
|
874 |
|
|
875 |
|
|
876 |
|
@param |
877 |
|
|
878 |
|
@return |
879 |
|
|
880 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
881 |
50
|
protected static boolean hexchar(char c){... |
882 |
50
|
return DIGIT(c) || (c>=A_CHAR && c<=F_CHAR) || (c>='a' && c<='f'); |
883 |
|
} |
884 |
|
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
@param |
890 |
|
|
891 |
|
@return |
892 |
|
|
893 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
894 |
78382
|
protected static boolean DIGIT(char c){... |
895 |
78382
|
return c>=ZERO_CHAR && c<=NINE_CHAR; |
896 |
|
} |
897 |
|
|
898 |
|
|
899 |
|
|
900 |
|
|
901 |
|
@param |
902 |
|
|
903 |
|
@return |
904 |
|
|
905 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
906 |
139170
|
protected static boolean ALPHA(char c){... |
907 |
139170
|
return (c>=A_CHAR && c<=Z_CHAR) || (c>=a_CHAR && c<=z_CHAR); |
908 |
|
|
909 |
|
} |
910 |
|
|
911 |
|
|
912 |
|
|
913 |
|
|
914 |
|
@param |
915 |
|
@param |
916 |
|
|
917 |
|
|
918 |
|
@return |
919 |
|
|
920 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 1 |
|
921 |
796853
|
protected static boolean QUOTATION(char c, boolean OSF){... |
922 |
796853
|
return c==(OSF?APOSTROPHE_CHAR:QUOTE_CHAR); |
923 |
|
} |
924 |
|
|
925 |
|
|
926 |
|
|
927 |
|
|
928 |
|
|
929 |
|
|
930 |
|
@param |
931 |
|
|
932 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
933 |
354700
|
protected static void skip_spaces(CharacterIterator ci){... |
934 |
354700
|
ci.previous(); |
935 |
358764
|
while(ci.next()==SPACE_CHAR); |
936 |
|
} |
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
|
@param |
944 |
|
|
945 |
|
@return |
946 |
|
|
947 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
948 |
836486
|
protected static boolean COMMA(char c){... |
949 |
836485
|
return c==COMMA_CHAR || c==SEMICOLON_CHAR; |
950 |
|
} |
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
|
955 |
|
|
956 |
|
|
957 |
|
@param |
958 |
|
|
959 |
|
@return |
960 |
|
|
961 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
962 |
796741
|
protected static boolean PLUS(char c){... |
963 |
796741
|
return c==PLUS_CHAR; |
964 |
|
} |
965 |
|
|
966 |
|
|
967 |
|
|
968 |
|
|
969 |
|
|
970 |
|
|
971 |
|
@param |
972 |
|
|
973 |
|
@return |
974 |
|
|
975 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
976 |
836510
|
protected static boolean ASSIGNMENT(char c){... |
977 |
836510
|
return c==ASSIGN_CHAR; |
978 |
|
} |
979 |
|
|
980 |
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
|
|
985 |
|
@param |
986 |
|
|
987 |
|
@return |
988 |
|
|
989 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
990 |
59
|
protected static boolean SLASH(char c){... |
991 |
59
|
return c==SLASH_CHAR; |
992 |
|
} |
993 |
|
|
994 |
|
|
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
@param |
1002 |
|
|
1003 |
|
@return |
1004 |
|
|
1005 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
1006 |
0
|
public static String toHexString(byte [] b){... |
1007 |
0
|
if (b==null) throw new IllegalArgumentException("Cannot convert null to hexstring"); |
1008 |
|
|
1009 |
0
|
if (b.length==0) return ""; |
1010 |
|
|
1011 |
0
|
StringBuffer result = new StringBuffer(HASH_CHAR); |
1012 |
|
|
1013 |
0
|
for (int i=0; i<b.length; i++){ |
1014 |
0
|
result.append(intToHex(b[i]>>4)); |
1015 |
0
|
result.append(intToHex(b[i])); |
1016 |
|
} |
1017 |
|
|
1018 |
0
|
return result.toString(); |
1019 |
|
} |
1020 |
|
|
1021 |
|
|
1022 |
|
|
1023 |
|
|
1024 |
|
@param |
1025 |
|
|
1026 |
|
@return |
1027 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1028 |
56
|
private static char intToHex(int a){ ... |
1029 |
56
|
a&=0xf; |
1030 |
56
|
return (char)((a<10)?(ZERO_CHAR+a): |
1031 |
|
(a_CHAR+a-10)); |
1032 |
|
} |
1033 |
|
|
1034 |
|
|
1035 |
|
|
1036 |
|
|
1037 |
|
|
1038 |
|
|
1039 |
|
|
1040 |
|
@param |
1041 |
|
|
1042 |
|
@return |
1043 |
|
|
1044 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 6 |
Complexity Density: 0.86 |
|
1045 |
52492
|
public static String escapeString(String s){... |
1046 |
52492
|
char [] c = s.toCharArray(); |
1047 |
52492
|
StringBuffer result = new StringBuffer(); |
1048 |
|
|
1049 |
431818
|
for (int i=0; i<c.length; i++){ |
1050 |
379326
|
if (!stringchar(c[i], false) || |
1051 |
|
(c[i]==SPACE_CHAR && |
1052 |
|
(i==0 || i==c.length-1) |
1053 |
|
) |
1054 |
|
){ |
1055 |
8
|
result.append(BSLASH_CHAR); |
1056 |
|
} |
1057 |
|
|
1058 |
379326
|
result.append(c[i]); |
1059 |
|
} |
1060 |
|
|
1061 |
52492
|
return toUTF8(result.toString()); |
1062 |
|
} |
1063 |
|
|
1064 |
|
|
1065 |
|
|
1066 |
|
|
1067 |
|
|
1068 |
|
|
1069 |
|
|
1070 |
|
@param |
1071 |
|
|
1072 |
|
@return |
1073 |
|
|
1074 |
|
|
1075 |
|
@see |
1076 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
1077 |
52492
|
private static String toUTF8(String s){... |
1078 |
52492
|
char [] c = s.toCharArray(); |
1079 |
52492
|
StringBuffer result = new StringBuffer(); |
1080 |
|
|
1081 |
431826
|
for (int i=0; i<c.length; i++){ |
1082 |
379334
|
if (c[i]<0x80){ |
1083 |
379320
|
result.append(c[i]); |
1084 |
|
}else{ |
1085 |
14
|
byte [] a = toUTF8(c[i]); |
1086 |
42
|
for (int j=0; j<a.length; j++){ |
1087 |
28
|
result.append(BSLASH_CHAR); |
1088 |
28
|
result.append(intToHex(a[j]>>4)); |
1089 |
28
|
result.append(intToHex(a[j])); |
1090 |
|
} |
1091 |
|
} |
1092 |
|
} |
1093 |
|
|
1094 |
52492
|
return result.toString(); |
1095 |
|
} |
1096 |
|
|
1097 |
|
|
1098 |
|
|
1099 |
|
|
1100 |
|
|
1101 |
|
@param |
1102 |
|
|
1103 |
|
@return |
1104 |
|
|
|
|
| 92.9% |
Uncovered Elements: 2 (28) |
Complexity: 5 |
Complexity Density: 0.25 |
|
1105 |
14
|
private static byte [] toUTF8(char c){... |
1106 |
14
|
byte [] b = new byte [6]; |
1107 |
14
|
int c_mask = 0x80; |
1108 |
14
|
int mask = 0; |
1109 |
14
|
int a = c; |
1110 |
|
|
1111 |
|
|
1112 |
14
|
int i; |
1113 |
28
|
for (i=0; i<b.length; i++){ |
1114 |
28
|
if (a<c_mask){ |
1115 |
14
|
b[i]=(byte)(mask | a); |
1116 |
14
|
break; |
1117 |
|
} |
1118 |
|
|
1119 |
14
|
b[i] = (byte)(0x80 | (a & 0x3f)); |
1120 |
|
|
1121 |
14
|
if (mask == 0){ |
1122 |
14
|
mask = 0x80; |
1123 |
14
|
c_mask >>>=1; |
1124 |
|
} |
1125 |
|
|
1126 |
14
|
mask |= c_mask; |
1127 |
14
|
c_mask >>>=1; |
1128 |
14
|
a >>>=6; |
1129 |
|
} |
1130 |
|
|
1131 |
14
|
byte [] result = new byte[ i + 1 ]; |
1132 |
42
|
for (int j=0; i>=0; i--, j++){ |
1133 |
28
|
result[j] = b[i]; |
1134 |
|
} |
1135 |
|
|
1136 |
14
|
return result; |
1137 |
|
} |
1138 |
|
|
1139 |
|
} |
1140 |
|
|