CryptoPrimitives implements CryptoSuite { @Override public void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes) throws CryptoException { if (certificatesBytes == null || certificatesBytes.size() == 0) { throw new CryptoException("List of CA certificates is empty. Nothing to load."); } StringBuilder sb = new StringBuilder(1000); ArrayList<Certificate> certList = new ArrayList<>(); for (byte[] certBytes : certificatesBytes) { if (null != diagnosticFileDumper) { sb.append("certificate to load:\n" + new String(certBytes)); } certList.add(bytesToCertificate(certBytes)); } loadCACertificates(certList); if (diagnosticFileDumper != null && sb.length() > 1) { logger.trace("loaded certificates: " + diagnosticFileDumper.createDiagnosticFile(sb.toString())); } } CryptoPrimitives(); Certificate bytesToCertificate(byte[] certBytes); PrivateKey bytesToPrivateKey(byte[] pemKey); @Override boolean verify(byte[] pemCertificate, String signatureAlgorithm, byte[] signature, byte[] plainText); KeyStore getTrustStore(); void addCACertificateToTrustStore(File caCertPem, String alias); void addCACertificateToTrustStore(byte[] bytes, String alias); @Override void loadCACertificates(Collection<Certificate> certificates); @Override void loadCACertificatesAsBytes(Collection<byte[]> certificatesBytes); @Override KeyPair keyGen(); @Override byte[] sign(PrivateKey key, byte[] data); String generateCertificationRequest(String subject, KeyPair pair); @Override byte[] hash(byte[] input); @Override CryptoSuiteFactory getCryptoSuiteFactory(); void init(); @Override Properties getProperties(); byte[] certificateToDER(String certificatePEM);  }
@Test (expected = CryptoException.class) public void testLoadCACertsBytesBadInput() throws CryptoException { crypto.loadCACertificatesAsBytes(null); }