85 public RDN(String name) throws IOException {
86 this(name, Collections.<String, String>emptyMap());
87 }
88
89 /**
90 * Constructs an RDN from its printable representation.
91 *
92 * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
93 * using '+' as a separator.
94 * If the '+' should be considered part of an AVA value, it must be
95 * preceded by '\'.
96 *
97 * @param name String form of RDN
98 * @param keyword an additional mapping of keywords to OIDs
99 * @throws IOException on parsing error
100 */
101 public RDN(String name, Map<String, String> keywordMap) throws IOException {
102 int quoteCount = 0;
103 int searchOffset = 0;
104 int avaOffset = 0;
105 List<AVA> avaVec = new ArrayList<AVA>(3);
106 int nextPlus = name.indexOf('+');
107 while (nextPlus >= 0) {
108 quoteCount += X500Name.countQuotes(name, searchOffset, nextPlus);
109 /*
110 * We have encountered an AVA delimiter (plus sign).
111 * If the plus sign in the RDN under consideration is
112 * preceded by a backslash (escape), or by a double quote, it
113 * is part of the AVA. Otherwise, it is used as a separator, to
114 * delimit the AVA under consideration from any subsequent AVAs.
115 */
116 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\'
117 && quoteCount != 1) {
118 /*
119 * Plus sign is a separator
120 */
121 String avaString = name.substring(avaOffset, nextPlus);
122 if (avaString.length() == 0) {
123 throw new IOException("empty AVA in RDN \"" + name + "\"");
124 }
125
165
166 /*
167 * Constructs an RDN from its printable representation.
168 *
169 * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
170 * using '+' as a separator.
171 * If the '+' should be considered part of an AVA value, it must be
172 * preceded by '\'.
173 *
174 * @param name String form of RDN
175 * @param keyword an additional mapping of keywords to OIDs
176 * @throws IOException on parsing error
177 */
178 RDN(String name, String format, Map<String, String> keywordMap)
179 throws IOException {
180 if (format.equalsIgnoreCase("RFC2253") == false) {
181 throw new IOException("Unsupported format " + format);
182 }
183 int searchOffset = 0;
184 int avaOffset = 0;
185 List<AVA> avaVec = new ArrayList<AVA>(3);
186 int nextPlus = name.indexOf('+');
187 while (nextPlus >= 0) {
188 /*
189 * We have encountered an AVA delimiter (plus sign).
190 * If the plus sign in the RDN under consideration is
191 * preceded by a backslash (escape), or by a double quote, it
192 * is part of the AVA. Otherwise, it is used as a separator, to
193 * delimit the AVA under consideration from any subsequent AVAs.
194 */
195 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\' ) {
196 /*
197 * Plus sign is a separator
198 */
199 String avaString = name.substring(avaOffset, nextPlus);
200 if (avaString.length() == 0) {
201 throw new IOException("empty AVA in RDN \"" + name + "\"");
202 }
203
204 // Parse AVA, and store it in vector
205 AVA ava = new AVA
436 * character.
437 */
438
439 // normally, an RDN only contains one AVA
440 if (assertion.length == 1) {
441 return canonical ? assertion[0].toRFC2253CanonicalString() :
442 assertion[0].toRFC2253String(oidMap);
443 }
444
445 StringBuilder relname = new StringBuilder();
446 if (!canonical) {
447 for (int i = 0; i < assertion.length; i++) {
448 if (i > 0) {
449 relname.append('+');
450 }
451 relname.append(assertion[i].toRFC2253String(oidMap));
452 }
453 } else {
454 // order the string type AVA's alphabetically,
455 // followed by the oid type AVA's numerically
456 List<AVA> avaList = new ArrayList<AVA>(assertion.length);
457 for (int i = 0; i < assertion.length; i++) {
458 avaList.add(assertion[i]);
459 }
460 java.util.Collections.sort(avaList, AVAComparator.getInstance());
461
462 for (int i = 0; i < avaList.size(); i++) {
463 if (i > 0) {
464 relname.append('+');
465 }
466 relname.append(avaList.get(i).toRFC2253CanonicalString());
467 }
468 }
469 return relname.toString();
470 }
471
472 }
473
474 class AVAComparator implements Comparator<AVA> {
475
476 private static final Comparator<AVA> INSTANCE = new AVAComparator();
|
85 public RDN(String name) throws IOException {
86 this(name, Collections.<String, String>emptyMap());
87 }
88
89 /**
90 * Constructs an RDN from its printable representation.
91 *
92 * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
93 * using '+' as a separator.
94 * If the '+' should be considered part of an AVA value, it must be
95 * preceded by '\'.
96 *
97 * @param name String form of RDN
98 * @param keyword an additional mapping of keywords to OIDs
99 * @throws IOException on parsing error
100 */
101 public RDN(String name, Map<String, String> keywordMap) throws IOException {
102 int quoteCount = 0;
103 int searchOffset = 0;
104 int avaOffset = 0;
105 List<AVA> avaVec = new ArrayList<>(3);
106 int nextPlus = name.indexOf('+');
107 while (nextPlus >= 0) {
108 quoteCount += X500Name.countQuotes(name, searchOffset, nextPlus);
109 /*
110 * We have encountered an AVA delimiter (plus sign).
111 * If the plus sign in the RDN under consideration is
112 * preceded by a backslash (escape), or by a double quote, it
113 * is part of the AVA. Otherwise, it is used as a separator, to
114 * delimit the AVA under consideration from any subsequent AVAs.
115 */
116 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\'
117 && quoteCount != 1) {
118 /*
119 * Plus sign is a separator
120 */
121 String avaString = name.substring(avaOffset, nextPlus);
122 if (avaString.length() == 0) {
123 throw new IOException("empty AVA in RDN \"" + name + "\"");
124 }
125
165
166 /*
167 * Constructs an RDN from its printable representation.
168 *
169 * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
170 * using '+' as a separator.
171 * If the '+' should be considered part of an AVA value, it must be
172 * preceded by '\'.
173 *
174 * @param name String form of RDN
175 * @param keyword an additional mapping of keywords to OIDs
176 * @throws IOException on parsing error
177 */
178 RDN(String name, String format, Map<String, String> keywordMap)
179 throws IOException {
180 if (format.equalsIgnoreCase("RFC2253") == false) {
181 throw new IOException("Unsupported format " + format);
182 }
183 int searchOffset = 0;
184 int avaOffset = 0;
185 List<AVA> avaVec = new ArrayList<>(3);
186 int nextPlus = name.indexOf('+');
187 while (nextPlus >= 0) {
188 /*
189 * We have encountered an AVA delimiter (plus sign).
190 * If the plus sign in the RDN under consideration is
191 * preceded by a backslash (escape), or by a double quote, it
192 * is part of the AVA. Otherwise, it is used as a separator, to
193 * delimit the AVA under consideration from any subsequent AVAs.
194 */
195 if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\' ) {
196 /*
197 * Plus sign is a separator
198 */
199 String avaString = name.substring(avaOffset, nextPlus);
200 if (avaString.length() == 0) {
201 throw new IOException("empty AVA in RDN \"" + name + "\"");
202 }
203
204 // Parse AVA, and store it in vector
205 AVA ava = new AVA
436 * character.
437 */
438
439 // normally, an RDN only contains one AVA
440 if (assertion.length == 1) {
441 return canonical ? assertion[0].toRFC2253CanonicalString() :
442 assertion[0].toRFC2253String(oidMap);
443 }
444
445 StringBuilder relname = new StringBuilder();
446 if (!canonical) {
447 for (int i = 0; i < assertion.length; i++) {
448 if (i > 0) {
449 relname.append('+');
450 }
451 relname.append(assertion[i].toRFC2253String(oidMap));
452 }
453 } else {
454 // order the string type AVA's alphabetically,
455 // followed by the oid type AVA's numerically
456 List<AVA> avaList = new ArrayList<>(assertion.length);
457 for (int i = 0; i < assertion.length; i++) {
458 avaList.add(assertion[i]);
459 }
460 java.util.Collections.sort(avaList, AVAComparator.getInstance());
461
462 for (int i = 0; i < avaList.size(); i++) {
463 if (i > 0) {
464 relname.append('+');
465 }
466 relname.append(avaList.get(i).toRFC2253CanonicalString());
467 }
468 }
469 return relname.toString();
470 }
471
472 }
473
474 class AVAComparator implements Comparator<AVA> {
475
476 private static final Comparator<AVA> INSTANCE = new AVAComparator();
|