CryptoPrimitives implements CryptoSuite { public void init() throws CryptoException, InvalidArgumentException { if (inited.getAndSet(true)) { throw new InvalidArgumentException("Crypto suite already initialized"); } else { resetConfiguration(); } } 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 public void testInitInvalidCertFormat() throws Exception { thrown.expect(CryptoException.class); String oldVal = null; try { oldVal = setConfigProperty(Config.CERTIFICATE_FORMAT, "abc123"); CryptoPrimitives crypto = new CryptoPrimitives(); crypto.init(); } finally { setConfigProperty(Config.CERTIFICATE_FORMAT, oldVal); } }