1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

Introduce ProviderFactory.

The goal is to become Provider-agnostic one day
This commit is contained in:
Paul Schaub 2020-01-09 20:20:51 +01:00
parent ed440e4434
commit 9a9f706e83
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,20 @@
package org.pgpainless.provider;
import java.security.Provider;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class BouncyCastleProviderFactory extends ProviderFactory {
private static final Provider provider = new BouncyCastleProvider();
@Override
public Provider _getProvider() {
return provider;
}
@Override
public String _getProviderName() {
return _getProvider().getName();
}
}

View file

@ -0,0 +1,24 @@
package org.pgpainless.provider;
import java.security.Provider;
public abstract class ProviderFactory {
private static ProviderFactory FACTORY = new BouncyCastleProviderFactory();
protected abstract Provider _getProvider();
protected abstract String _getProviderName();
public static void setFactory(ProviderFactory factory) {
ProviderFactory.FACTORY = factory;
}
public static Provider getProvider() {
return ProviderFactory.FACTORY._getProvider();
}
public static String getProviderName() {
return ProviderFactory.FACTORY._getProviderName();
}
}

View file

@ -0,0 +1,14 @@
package org.pgpainless;
import static junit.framework.TestCase.assertEquals;
import org.junit.Test;
import org.pgpainless.provider.ProviderFactory;
public class ProviderFactoryTest {
@Test
public void providerFactoryDefaultIsBouncyCastleTest() {
assertEquals("BC", ProviderFactory.getProviderName());
}
}