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:
parent
ed440e4434
commit
9a9f706e83
3 changed files with 58 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue