use of org.bouncycastle.asn1.DERUniversalString in project XobotOS by xamarin.
the class IETFUtils method valueToString.
public static String valueToString(ASN1Encodable value) {
StringBuffer vBuf = new StringBuffer();
if (value instanceof ASN1String && !(value instanceof DERUniversalString)) {
String v = ((ASN1String) value).getString();
if (v.length() > 0 && v.charAt(0) == '#') {
vBuf.append("\\" + v);
} else {
vBuf.append(v);
}
} else {
vBuf.append("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded())));
}
int end = vBuf.length();
int index = 0;
if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#') {
index += 2;
}
while (index != end) {
if ((vBuf.charAt(index) == ',') || (vBuf.charAt(index) == '"') || (vBuf.charAt(index) == '\\') || (vBuf.charAt(index) == '+') || (vBuf.charAt(index) == '=') || (vBuf.charAt(index) == '<') || (vBuf.charAt(index) == '>') || (vBuf.charAt(index) == ';')) {
vBuf.insert(index, "\\");
index++;
end++;
}
index++;
}
return vBuf.toString();
}
use of org.bouncycastle.asn1.DERUniversalString in project robovm by robovm.
the class IETFUtils method valueToString.
public static String valueToString(ASN1Encodable value) {
StringBuffer vBuf = new StringBuffer();
if (value instanceof ASN1String && !(value instanceof DERUniversalString)) {
String v = ((ASN1String) value).getString();
if (v.length() > 0 && v.charAt(0) == '#') {
vBuf.append("\\" + v);
} else {
vBuf.append(v);
}
} else {
try {
vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
} catch (IOException e) {
throw new IllegalArgumentException("Other value has no encoded form");
}
}
int end = vBuf.length();
int index = 0;
if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#') {
index += 2;
}
while (index != end) {
if ((vBuf.charAt(index) == ',') || (vBuf.charAt(index) == '"') || (vBuf.charAt(index) == '\\') || (vBuf.charAt(index) == '+') || (vBuf.charAt(index) == '=') || (vBuf.charAt(index) == '<') || (vBuf.charAt(index) == '>') || (vBuf.charAt(index) == ';')) {
vBuf.insert(index, "\\");
index++;
end++;
}
index++;
}
int start = 0;
if (vBuf.length() > 0) {
while (vBuf.charAt(start) == ' ') {
vBuf.insert(start, "\\");
start += 2;
}
}
int endBuf = vBuf.length() - 1;
while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ') {
vBuf.insert(endBuf, '\\');
endBuf--;
}
return vBuf.toString();
}
Aggregations