/** * Format an AS.1 string from the given decoder as a string. * * @param decoder the ASN.1 decoder * @return the formatted string */ public static String formatAsn1(ASN1Decoder decoder) { final StringBuilder builder = new StringBuilder(); formatAsn1(decoder, builder); return builder.toString(); }
/** * Decodes an OID and resolve its corresponding key algorithm. * * @return the key algorithm associated with the OID or null if no algorithm could be resolved */ public String decodeObjectIdentifierAsKeyAlgorithm() { return keyAlgorithmFromOid(decodeObjectIdentifier()); }
@Override public void encodePrintableString(final byte[] str) { for (byte b : str) { validatePrintableByte(b & 0xff); } writeElement(PRINTABLE_STRING_TYPE, str); }
final String signatureAlgorithmOid = ASN1.oidFromSignatureAlgorithm(signatureAlgorithmName); if (signatureAlgorithmOid == null) { throw log.asnUnrecognisedAlgorithm(signatureAlgorithmName);
signatureAlgorithmOid = ASN1.oidFromSignatureAlgorithm(signatureAlgorithmName); if (signatureAlgorithmOid == null) { throw log.asnUnrecognisedAlgorithm(signatureAlgorithmName);
@Override public void encodePrintableString(final String str) { for (int i = 0; i < str.length(); i = str.offsetByCodePoints(i, 1)) { validatePrintableByte(str.codePointAt(i)); } writeElement(PRINTABLE_STRING_TYPE, str.getBytes(StandardCharsets.US_ASCII)); }
throw log.noSignatureAlgorithmNameGiven(); final String signatureAlgorithmOid = ASN1.oidFromSignatureAlgorithm(signatureAlgorithmName); if (signatureAlgorithmOid == null) { throw log.unknownSignatureAlgorithmName(signatureAlgorithmName);
builder.append("[sequence:"); decoder.startSequence(); formatAsn1(decoder, builder); decoder.endSequence(); builder.append(']'); builder.append("[set:"); decoder.startSet(); formatAsn1(decoder, builder); decoder.endSet(); builder.append(']');
@Override public byte[] decodePrintableStringAsBytes() throws ASN1Exception { readTag(PRINTABLE_STRING_TYPE); final int length = readLength(); int c = 0; byte[] result = new byte[length]; while (bi.hasNext() && c < length) { final int b = bi.next(); validatePrintableByte(b); result[c++] = (byte) b; } if (c < length) { throw log.asnUnexpectedEndOfInput(); } return result; }