private NoSuchAlgorithmException notFound(String serviceName, String algorithm) throws NoSuchAlgorithmException { throw new NoSuchAlgorithmException(serviceName + " " + algorithm + " implementation not found"); } }
private static NoSuchAlgorithmException invalidTransformation(String transformation) throws NoSuchAlgorithmException { throw new NoSuchAlgorithmException("Invalid transformation: " + transformation); }
public static String messageDigestAlgorithm(String algorithm) throws NoSuchAlgorithmException { switch (algorithm) { case ALGORITHM_OTP_MD5: return MD5; case ALGORITHM_OTP_SHA1: return SHA1; case ALGORITHM_OTP_SHA_256: return SHA256; case ALGORITHM_OTP_SHA_384: return SHA384; case ALGORITHM_OTP_SHA_512: return SHA512; default: throw new NoSuchAlgorithmException(); } }
/** Initialize the checksum interface. */ public void initChecksum() { if (checksum != null) { return; } if ("CRC".equals(algorithm)) { checksum = new CRC32(); } else if ("ADLER".equals(algorithm)) { checksum = new Adler32(); } else { throw new BuildException(new NoSuchAlgorithmException()); } }
public static Fingerprinter getInstance(String name) throws NoSuchAlgorithmException { try { Class<?> clazz = Class.forName(Fingerprinter.class.getPackage().getName()+"."+name+Fingerprinter.class.getSimpleName()); return (Fingerprinter) clazz.newInstance(); } catch (Exception e) { throw new NoSuchAlgorithmException("No such fingerprinting algorithm: "+name, e); } }
/** * Constructor for DefaultX509TrustManager. * */ public DefaultX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException { super(); TrustManagerFactory factory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); factory.init(keystore); TrustManager[] trustmanagers = factory.getTrustManagers(); if (trustmanagers.length == 0) { throw new NoSuchAlgorithmException("SunX509 trust manager not supported"); } this.standardTrustManager = (X509TrustManager) trustmanagers[0]; }
public static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException { switch (algorithm) { case ALGORITHM_OTP_MD5: return MessageDigest.getInstance("MD5"); case ALGORITHM_OTP_SHA1: return MessageDigest.getInstance("SHA-1"); case ALGORITHM_OTP_SHA_256: return MessageDigest.getInstance("SHA-256"); case ALGORITHM_OTP_SHA_384: return MessageDigest.getInstance("SHA-384"); case ALGORITHM_OTP_SHA_512: return MessageDigest.getInstance("SHA-512"); default: throw new NoSuchAlgorithmException(); } }
/** * Constructor for EasyX509TrustManager. */ public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException { super(); TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); factory.init(keystore); TrustManager[] trustmanagers = factory.getTrustManagers(); if (trustmanagers.length == 0) { throw new NoSuchAlgorithmException("no trust manager found"); } standardTrustManager = (X509TrustManager) trustmanagers[0]; }
private static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException { switch (algorithm) { case ALGORITHM_OTP_MD5: return MessageDigest.getInstance("MD5"); case ALGORITHM_OTP_SHA1: return MessageDigest.getInstance("SHA-1"); case ALGORITHM_OTP_SHA_256: return MessageDigest.getInstance("SHA-256"); case ALGORITHM_OTP_SHA_384: return MessageDigest.getInstance("SHA-384"); case ALGORITHM_OTP_SHA_512: return MessageDigest.getInstance("SHA-512"); default: throw new NoSuchAlgorithmException(); } }
static int get(String algorithm, String mode) throws NoSuchAlgorithmException { try { return AlgMode.valueOf(algorithm + "_" + mode).ordinal(); } catch (Exception e) { throw new NoSuchAlgorithmException("Doesn't support algorithm: " + algorithm + " and mode: " + mode); } } }
@Override public final NoSuchAlgorithmException noAlgorithmForPassword(final String alias) { final NoSuchAlgorithmException result = new NoSuchAlgorithmException(String.format(getLoggingLocale(), noAlgorithmForPassword$str(), alias)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String unexpectedWhitespaceInPasswordFile = "ELY02006: Unexpected whitespace in password file";
@Override public final NoSuchAlgorithmException noDefaultTrustManager() { final NoSuchAlgorithmException result = new NoSuchAlgorithmException(String.format(getLoggingLocale(), noDefaultTrustManager$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String noContextForSslConnection = "ELY04006: No context for SSL connection";
@Override public final NoSuchAlgorithmException noAlgorithmForSslProtocol() { final NoSuchAlgorithmException result = new NoSuchAlgorithmException(String.format(getLoggingLocale(), noAlgorithmForSslProtocol$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String emptyChainNotTrusted = "ELY04002: Empty certificate chain is not trusted";
@Override public final NoSuchAlgorithmException noDefaultKeyManager() { final NoSuchAlgorithmException result = new NoSuchAlgorithmException(String.format(getLoggingLocale(), noDefaultKeyManager$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String defaultContextCannotBeNull = "ELY04029: Default context cannot be null";
@Override public final NoSuchAlgorithmException noSuchAlgorithmInvalidAlgorithm(final String algorithm) { final NoSuchAlgorithmException result = new NoSuchAlgorithmException(String.format(getLoggingLocale(), noSuchAlgorithmInvalidAlgorithm$str(), algorithm)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String couldNotObtainKeySpecEncodingIdentifier = "ELY08029: Could not obtain key spec encoding identifier.";
@Override public final NoSuchAlgorithmException noSuchAlgorithmCreateService(final String serviceType, final String algorithm, final Throwable cause) { final NoSuchAlgorithmException result = new NoSuchAlgorithmException(String.format(getLoggingLocale(), noSuchAlgorithmCreateService$str(), serviceType, algorithm), cause); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String unableToLoadOidsFromPropertiesFile = "ELY00012: Unable to load OIDs database from properties file";
/** * Get a {@code CredentialStore} instance. The returned CredentialStore object will implement the given algorithm. * * @param algorithm the name of the algorithm * @param provider the provider to use * @return a {@code CredentialStore} instance * @throws NoSuchAlgorithmException if the given algorithm has no available implementations */ public static CredentialStore getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException { final Provider.Service service = provider.getService(CREDENTIAL_STORE_TYPE, algorithm); if (service == null) throw new NoSuchAlgorithmException(algorithm); return new CredentialStore(provider, (CredentialStoreSpi) service.newInstance(null), algorithm); }
/** * Get a {@code CredentialStore} instance. The returned CredentialStore object will implement the given algorithm. * * @param algorithm the name of the algorithm * @param providers supplier of provider instances to search. * @return a {@code CredentialStore} instance * @throws NoSuchAlgorithmException if the given algorithm has no available implementations */ public static CredentialStore getInstance(String algorithm, Supplier<Provider[]> providers) throws NoSuchAlgorithmException { checkNotNullParam("providers", providers); for (Provider provider : providers.get()) { final Provider.Service service = provider.getService(CREDENTIAL_STORE_TYPE, algorithm); if (service != null) { return new CredentialStore(provider, (CredentialStoreSpi) service.newInstance(null), algorithm); } } throw new NoSuchAlgorithmException(); }
/** * Finds the appropriate service implementation and returns and * instance of the class that implements corresponding Service * Provider Interface. */ public Object getInstance(String algorithm, Provider provider, Object param) throws NoSuchAlgorithmException { if (algorithm == null) { throw new NoSuchAlgorithmException("algorithm == null"); } Provider.Service service = provider.getService(serviceName, algorithm); if (service == null) { throw notFound(serviceName, algorithm); } return service.newInstance(param); }
@Test(expected = MessagingException.class) public void open_whenTrustedSocketFactoryThrowsGeneralSecurityException_throwMessagingException() throws Exception { when(mockTrustedSocketFactory.createSocket(null, host, port, null)).thenThrow( new NoSuchAlgorithmException("")); addSettingsForValidMockSocket(); settings.setAuthType(AuthType.PLAIN); Pop3Connection connection = new Pop3Connection(settings, mockTrustedSocketFactory); connection.open(); }