mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-12 15:21:08 +01:00
Kotlin conversion: ProviderFactory
This commit is contained in:
parent
8351223614
commit
11c1c54111
8 changed files with 63 additions and 92 deletions
|
|
@ -1,23 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.provider;
|
||||
|
||||
import java.security.Provider;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ProviderFactory} using a {@link BouncyCastleProvider}.
|
||||
*/
|
||||
public final class BouncyCastleProviderFactory extends ProviderFactory {
|
||||
|
||||
private static final Provider provider = new BouncyCastleProvider();
|
||||
|
||||
@Override
|
||||
public Provider _getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.provider;
|
||||
|
||||
import java.security.Provider;
|
||||
|
||||
/**
|
||||
* Allow the use of different {@link Provider} implementations to provide cryptographic primitives by setting
|
||||
* a {@link ProviderFactory} singleton.
|
||||
* By default, the class is initialized with a {@link BouncyCastleProviderFactory}.
|
||||
* <br>
|
||||
* To make use of your own custom {@link Provider}, call {@link #setFactory(ProviderFactory)}, passing your
|
||||
* own custom {@link ProviderFactory} instance.
|
||||
*/
|
||||
public abstract class ProviderFactory {
|
||||
|
||||
private static ProviderFactory FACTORY;
|
||||
|
||||
protected abstract Provider _getProvider();
|
||||
|
||||
protected String _getProviderName() {
|
||||
return _getProvider().getName();
|
||||
}
|
||||
|
||||
public static void setFactory(ProviderFactory factory) {
|
||||
ProviderFactory.FACTORY = factory;
|
||||
}
|
||||
|
||||
public static ProviderFactory getFactory() {
|
||||
if (FACTORY == null) {
|
||||
FACTORY = new BouncyCastleProviderFactory();
|
||||
}
|
||||
return FACTORY;
|
||||
}
|
||||
|
||||
public static Provider getProvider() {
|
||||
return ProviderFactory.getFactory()._getProvider();
|
||||
}
|
||||
|
||||
public static String getProviderName() {
|
||||
return ProviderFactory.getFactory()._getProviderName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* Classes that allow setting a custom implementation of {@link java.security.Provider}.
|
||||
*/
|
||||
package org.pgpainless.provider;
|
||||
Loading…
Add table
Add a link
Reference in a new issue