use of org.bouncycastle.asn1.ASN1String in project robovm by robovm.
the class IETFUtils method canonicalize.
public static String canonicalize(String s) {
String value = Strings.toLowerCase(s.trim());
if (value.length() > 0 && value.charAt(0) == '#') {
ASN1Primitive obj = decodeObject(value);
if (obj instanceof ASN1String) {
value = Strings.toLowerCase(((ASN1String) obj).getString().trim());
}
}
value = stripInternalSpaces(value);
return value;
}
use of org.bouncycastle.asn1.ASN1String in project XobotOS by xamarin.
the class X509ExtensionUtil method getAlternativeNames.
private static Collection getAlternativeNames(byte[] extVal) throws CertificateParsingException {
if (extVal == null) {
return Collections.EMPTY_LIST;
}
try {
Collection temp = new ArrayList();
Enumeration it = DERSequence.getInstance(fromExtensionValue(extVal)).getObjects();
while (it.hasMoreElements()) {
GeneralName genName = GeneralName.getInstance(it.nextElement());
List list = new ArrayList();
// BEGIN android-changed
list.add(Integer.valueOf(genName.getTagNo()));
// END android-changed
switch(genName.getTagNo()) {
case GeneralName.ediPartyName:
case GeneralName.x400Address:
case GeneralName.otherName:
list.add(genName.getName().getDERObject());
break;
case GeneralName.directoryName:
list.add(X509Name.getInstance(genName.getName()).toString());
break;
case GeneralName.dNSName:
case GeneralName.rfc822Name:
case GeneralName.uniformResourceIdentifier:
list.add(((ASN1String) genName.getName()).getString());
break;
case GeneralName.registeredID:
list.add(DERObjectIdentifier.getInstance(genName.getName()).getId());
break;
case GeneralName.iPAddress:
list.add(DEROctetString.getInstance(genName.getName()).getOctets());
break;
default:
throw new IOException("Bad tag number: " + genName.getTagNo());
}
temp.add(list);
}
return Collections.unmodifiableCollection(temp);
} catch (Exception e) {
throw new CertificateParsingException(e.getMessage());
}
}
use of org.bouncycastle.asn1.ASN1String 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.ASN1String in project XobotOS by xamarin.
the class IETFUtils method canonicalize.
public static String canonicalize(String s) {
String value = Strings.toLowerCase(s.trim());
if (value.length() > 0 && value.charAt(0) == '#') {
DERObject obj = decodeObject(value);
if (obj instanceof ASN1String) {
value = Strings.toLowerCase(((ASN1String) obj).getString().trim());
}
}
value = stripInternalSpaces(value);
return value;
}
use of org.bouncycastle.asn1.ASN1String in project robovm by robovm.
the class X509CertificateObject method getAlternativeNames.
private static Collection getAlternativeNames(byte[] extVal) throws CertificateParsingException {
if (extVal == null) {
return null;
}
try {
Collection temp = new ArrayList();
Enumeration it = ASN1Sequence.getInstance(extVal).getObjects();
while (it.hasMoreElements()) {
GeneralName genName = GeneralName.getInstance(it.nextElement());
List list = new ArrayList();
list.add(Integers.valueOf(genName.getTagNo()));
switch(genName.getTagNo()) {
case GeneralName.ediPartyName:
case GeneralName.x400Address:
case GeneralName.otherName:
list.add(genName.getEncoded());
break;
case GeneralName.directoryName:
// BEGIN android-changed
list.add(X509Name.getInstance(genName.getName()).toString(true, X509Name.DefaultSymbols));
// END android-changed
break;
case GeneralName.dNSName:
case GeneralName.rfc822Name:
case GeneralName.uniformResourceIdentifier:
list.add(((ASN1String) genName.getName()).getString());
break;
case GeneralName.registeredID:
list.add(ASN1ObjectIdentifier.getInstance(genName.getName()).getId());
break;
case GeneralName.iPAddress:
byte[] addrBytes = DEROctetString.getInstance(genName.getName()).getOctets();
final String addr;
try {
addr = InetAddress.getByAddress(addrBytes).getHostAddress();
} catch (UnknownHostException e) {
continue;
}
list.add(addr);
break;
default:
throw new IOException("Bad tag number: " + genName.getTagNo());
}
temp.add(Collections.unmodifiableList(list));
}
if (temp.size() == 0) {
return null;
}
return Collections.unmodifiableCollection(temp);
} catch (Exception e) {
throw new CertificateParsingException(e.getMessage());
}
}
Aggregations