< prev index next > src/java.base/share/classes/sun/security/x509/AVA.java
Print this page
* RFC 4514.
*/
private static final String specialCharsDefault = ",=\n+<>#;\\\" ";
private static final String escapedDefault = ",+<>;\"";
- /*
- * Values that aren't printable strings are emitted as BER-encoded
- * hex data.
- */
- private static final String hexDigits = "0123456789ABCDEF";
-
public AVA(ObjectIdentifier type, DerValue val) {
if ((type == null) || (val == null)) {
throw new NullPointerException();
}
oid = type;
if (isTerminator(c, format)) {
break;
}
! int cVal = hexDigits.indexOf(Character.toUpperCase((char)c));
! if (cVal == -1) {
throw new IOException("AVA parse, invalid hex " +
"digit: "+ (char)c);
}
if ((cNdx % 2) == 1) {
if (isTerminator(c, format)) {
break;
}
! int cVal = Hex.decoder().fromHex(c);
! if (cVal < 0) {
throw new IOException("AVA parse, invalid hex " +
"digit: "+ (char)c);
}
if ((cNdx % 2) == 1) {
}
}
private static Byte getEmbeddedHexPair(int c1, Reader in)
throws IOException {
!
! if (hexDigits.indexOf(Character.toUpperCase((char)c1)) >= 0) {
int c2 = readChar(in, "unexpected EOF - " +
"escaped hex value must include two valid digits");
! if (hexDigits.indexOf(Character.toUpperCase((char)c2)) >= 0) {
! int hi = Character.digit((char)c1, 16);
- int lo = Character.digit((char)c2, 16);
return (byte)((hi<<4) + lo);
} else {
throw new IOException
("escaped hex value must include two valid digits");
}
}
}
private static Byte getEmbeddedHexPair(int c1, Reader in)
throws IOException {
! Hex.Decoder dec = Hex.decoder();
! int hi = dec.fromHex(c1);
+ if (hi >= 0) {
int c2 = readChar(in, "unexpected EOF - " +
"escaped hex value must include two valid digits");
! int lo = dec.fromHex(c2);
! if (lo >= 0) {
return (byte)((hi<<4) + lo);
} else {
throw new IOException
("escaped hex value must include two valid digits");
}
* syntax for individual attribute/value assertions. It
* emits standardised keywords, as well as keywords contained in the
* OID/keyword map.
*/
public String toRFC2253String(Map<String, String> oidMap) {
+ Hex.Encoder enc = Hex.encoder();
/*
* Section 2.3: The AttributeTypeAndValue is encoded as the string
* representation of the AttributeType, followed by an equals character
* ('=' ASCII 61), followed by the string representation of the
* AttributeValue. The encoding of the AttributeValue is given in
data = value.toByteArray();
} catch (IOException ie) {
throw new IllegalArgumentException("DER Value conversion");
}
typeAndValue.append('#');
! for (int j = 0; j < data.length; j++) {
- byte b = data[j];
- typeAndValue.append(Character.forDigit(0xF & (b >>> 4), 16));
- typeAndValue.append(Character.forDigit(0xF & b, 16));
- }
} else {
/*
* 2.4 (cont): Otherwise, if the AttributeValue is of a type which
* has a string representation, the value is converted first to a
* UTF-8 string according to its syntax specification.
data = value.toByteArray();
} catch (IOException ie) {
throw new IllegalArgumentException("DER Value conversion");
}
typeAndValue.append('#');
! enc.encode(typeAndValue, data);
} else {
/*
* 2.4 (cont): Otherwise, if the AttributeValue is of a type which
* has a string representation, the value is converted first to a
* UTF-8 string according to its syntax specification.
// embed non-printable/non-escaped char
// as escaped hex pairs for debugging
byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
! char hexChar = Character.forDigit
- (0xF & (valueBytes[j] >>> 4), 16);
- sbuffer.append(Character.toUpperCase(hexChar));
- hexChar = Character.forDigit
- (0xF & (valueBytes[j]), 16);
- sbuffer.append(Character.toUpperCase(hexChar));
}
} else {
// append non-printable/non-escaped char
sbuffer.append(c);
// embed non-printable/non-escaped char
// as escaped hex pairs for debugging
byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
! enc.encodeHexPair(sbuffer, valueBytes[j]);
}
} else {
// append non-printable/non-escaped char
sbuffer.append(c);
}
return typeAndValue.toString();
}
public String toRFC2253CanonicalString() {
+ Hex.Encoder enc = Hex.encoder();
/*
* Section 2.3: The AttributeTypeAndValue is encoded as the string
* representation of the AttributeType, followed by an equals character
* ('=' ASCII 61), followed by the string representation of the
* AttributeValue. The encoding of the AttributeValue is given in
data = value.toByteArray();
} catch (IOException ie) {
throw new IllegalArgumentException("DER Value conversion");
}
typeAndValue.append('#');
! for (int j = 0; j < data.length; j++) {
- byte b = data[j];
- typeAndValue.append(Character.forDigit(0xF & (b >>> 4), 16));
- typeAndValue.append(Character.forDigit(0xF & b, 16));
- }
} else {
/*
* 2.4 (cont): Otherwise, if the AttributeValue is of a type which
* has a string representation, the value is converted first to a
* UTF-8 string according to its syntax specification.
data = value.toByteArray();
} catch (IOException ie) {
throw new IllegalArgumentException("DER Value conversion");
}
typeAndValue.append('#');
! enc.encode(typeAndValue, data);
} else {
/*
* 2.4 (cont): Otherwise, if the AttributeValue is of a type which
* has a string representation, the value is converted first to a
* UTF-8 string according to its syntax specification.
continue;
}
}
} else if (debug != null && Debug.isOn("ava")) {
-
// embed non-printable/non-escaped char
// as escaped hex pairs for debugging
previousWhite = false;
byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
! sbuffer.append(Character.forDigit
- (0xF & (valueBytes[j] >>> 4), 16));
- sbuffer.append(Character.forDigit
- (0xF & (valueBytes[j]), 16));
}
} else {
// append non-printable/non-escaped char
continue;
}
}
} else if (debug != null && Debug.isOn("ava")) {
// embed non-printable/non-escaped char
// as escaped hex pairs for debugging
previousWhite = false;
byte[] valueBytes = Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
! enc.encodeHexPair(sbuffer, valueBytes[j]);
}
} else {
// append non-printable/non-escaped char
* Construct the value with as little copying and garbage
* production as practical. First the keyword (mandatory),
* then the equals sign, finally the value.
*/
StringBuilder retval = new StringBuilder(40);
!
retval.append(keyword);
retval.append('=');
try {
String valStr = value.getAsString();
* Construct the value with as little copying and garbage
* production as practical. First the keyword (mandatory),
* then the equals sign, finally the value.
*/
StringBuilder retval = new StringBuilder(40);
! Hex.Encoder enc = Hex.encoder();
retval.append(keyword);
retval.append('=');
try {
String valStr = value.getAsString();
// when the value is not a string type
byte[] data = value.toByteArray();
retval.append('#');
! for (int i = 0; i < data.length; i++) {
- retval.append(hexDigits.charAt((data [i] >> 4) & 0x0f));
- retval.append(hexDigits.charAt(data [i] & 0x0f));
- }
-
} else {
boolean quoteNeeded = false;
StringBuilder sbuffer = new StringBuilder();
boolean previousWhite = false;
// when the value is not a string type
byte[] data = value.toByteArray();
retval.append('#');
! enc.encode(retval, data);
} else {
boolean quoteNeeded = false;
StringBuilder sbuffer = new StringBuilder();
boolean previousWhite = false;
// embed escaped hex pairs
byte[] valueBytes =
Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
! char hexChar = Character.forDigit
- (0xF & (valueBytes[j] >>> 4), 16);
- sbuffer.append(Character.toUpperCase(hexChar));
- hexChar = Character.forDigit
- (0xF & (valueBytes[j]), 16);
- sbuffer.append(Character.toUpperCase(hexChar));
}
} else {
// append non-printable/non-escaped char
// embed escaped hex pairs
byte[] valueBytes =
Character.toString(c).getBytes(UTF_8);
for (int j = 0; j < valueBytes.length; j++) {
sbuffer.append('\\');
! enc.encodeHexPair(sbuffer, valueBytes[j]);
}
} else {
// append non-printable/non-escaped char
< prev index next >