Inline hex-encoded ASN.1 must be exactly one object
also refactor hex decoding
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DERPrintableString;
import org.bouncycastle.util.Strings;
+import org.bouncycastle.util.encoders.Hex;
/**
* It turns out that the number of standard ways the fields in a DN should be
@@ -62,34 +63,7 @@ protected ASN1Primitive convertHexEncoded(
int off)
throws IOException
{
- str = Strings.toLowerCase(str);
- byte[] data = new byte[(str.length() - off) / 2];
- for (int index = 0; index != data.length; index++)
- {
- char left = str.charAt((index * 2) + off);
- char right = str.charAt((index * 2) + off + 1);
-
- if (left < 'a')
- {
- data[index] = (byte)((left - '0') << 4);
- }
- else
- {
- data[index] = (byte)((left - 'a' + 10) << 4);
- }
- if (right < 'a')
- {
- data[index] |= (byte)(right - '0');
- }
- else
- {
- data[index] |= (byte)(right - 'a' + 10);
- }
- }
-
- ASN1InputStream aIn = new ASN1InputStream(data);
-
- return aIn.readObject();
+ return ASN1Primitive.fromByteArray(Hex.decodeStrict(str, off, str.length() - off));
}
/**
