/** * Converts bytes in the buffer to a DN by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the DN and the * limit is set beyond the last byte of DN data. * * @return decoded bytes as a DN */ public static DN decode(final ByteBuffer encoded) { return new DN(RDN.decode(encoded)); }
@Override public String toString() { return String.format("[%s@%d::rdns=%s]", getClass().getName(), hashCode(), Arrays.toString(rdns)); } }
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<>(); final byte[] encodedDn = cert.getSubjectX500Principal().getEncoded(); if (encodedDn != null && encodedDn.length > 0) { final DN dn = DN.decode(ByteBuffer.wrap(encodedDn)); for (RDN rdn : dn.getRDNs()) { // for multi value RDNs the first value is used final String value = rdn.getAttributeValue("2.5.4.3", new StringValueTranscoder()); if (value != null) { names.add(value); } } } return names.toArray(new String[names.size()]); }
/** * @param bytes to decode. * @param expected to compare. * * @throws Exception On test failure. */ @Test(groups = {"asn1"}, dataProvider = "dns") public void decode(final byte[] bytes, final DN expected) throws Exception { Assert.assertEquals(DN.decode(ByteBuffer.wrap(bytes)), expected); }
/** * @param expected bytes to compare. * @param sequence to encode. * * @throws Exception On test failure. */ @Test(groups = {"asn1"}, dataProvider = "dns") public void encode(final byte[] expected, final DN sequence) throws Exception { Assert.assertEquals(sequence.encode(), expected); } }
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<>(); final byte[] encodedDn = cert.getSubjectX500Principal().getEncoded(); if (encodedDn != null && encodedDn.length > 0) { final DN dn = DN.decode(ByteBuffer.wrap(encodedDn)); for (RDN rdn : dn.getRDNs()) { // for multi value RDNs the first value is used final String value = rdn.getAttributeValue("2.5.4.3", new StringValueTranscoder()); if (value != null) { names.add(value); } } } return names.toArray(new String[names.size()]); }
/** * Returns the CNs from the supplied certificate. * * @param cert to get CNs from * * @return CNs */ private String[] getCNs(final X509Certificate cert) { final List<String> names = new ArrayList<>(); final byte[] encodedDn = cert.getSubjectX500Principal().getEncoded(); if (encodedDn != null && encodedDn.length > 0) { final DN dn = DN.decode(ByteBuffer.wrap(encodedDn)); for (RDN rdn : dn.getRDNs()) { // for multi value RDNs the first value is used final String value = rdn.getAttributeValue("2.5.4.3", new StringValueTranscoder()); if (value != null) { names.add(value); } } } return names.toArray(new String[names.size()]); }
/** * Converts bytes in the buffer to a DN by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the DN and the * limit is set beyond the last byte of DN data. * * @return decoded bytes as a DN */ public static DN decode(final ByteBuffer encoded) { return new DN(RDN.decode(encoded)); }
@Override public String toString() { return String.format("[%s@%d::rdns=%s]", getClass().getName(), hashCode(), Arrays.toString(rdns)); } }
/** * Converts bytes in the buffer to a DN by reading from the current position to the limit. * * @param encoded buffer containing DER-encoded data where the buffer is positioned at the tag of the DN and the * limit is set beyond the last byte of DN data. * * @return decoded bytes as a DN */ public static DN decode(final ByteBuffer encoded) { return new DN(RDN.decode(encoded)); }
@Override public String toString() { return String.format("[%s@%d::rdns=%s]", getClass().getName(), hashCode(), Arrays.toString(rdns)); } }