TrustedAuthorityParser extends Parser<TrustedAuthority> { @Override public TrustedAuthority parse() { TrustedAuthority authority = new TrustedAuthority(); authority.setIdentifierType(parseByteField(ExtensionByteLength.TRUSTED_AUTHORITY_TYPE)); switch (TrustedCaIndicationIdentifierType.getIdentifierByByte(authority.getIdentifierType().getValue())) { case PRE_AGREED: break; case CERT_SHA1_HASH: case KEY_SHA1_HASH: authority.setSha1Hash(parseByteArrayField(ExtensionByteLength.TRUSTED_AUTHORITY_HASH)); break; case X509_NAME: authority .setDistinguishedNameLength(parseIntField(ExtensionByteLength.TRUSTED_AUTHORITY_DISTINGUISHED_NAME_LENGTH)); authority.setDistinguishedName(parseByteArrayField(authority.getDistinguishedNameLength().getValue())); break; default: LOGGER.warn("Couldn't set the trusted authority to reasonable values"); break; } return authority; } TrustedAuthorityParser(int startposition, byte[] array); @Override TrustedAuthority parse();  }
@Test public void parse() { TrustedAuthorityParser parser = new TrustedAuthorityParser(0, parserBytes); TrustedAuthority authority = parser.parse(); assertEquals(identifier.getValue(), (long) authority.getIdentifierType().getValue()); if (hash != null) { assertArrayEquals(hash, authority.getSha1Hash().getValue()); } else { assertNull(authority.getSha1Hash()); } if (distNameLength != null) { assertEquals(distNameLength, authority.getDistinguishedNameLength().getValue()); } else { assertNull(authority.getDistinguishedNameLength()); } if (distName != null) { assertArrayEquals(distName, authority.getDistinguishedName().getValue()); } else { assertNull(authority.getDistinguishedName()); } }