mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 20:32:05 +01:00
More missing javadoc
This commit is contained in:
parent
b58861635d
commit
a50c2d9714
6 changed files with 66 additions and 0 deletions
|
@ -41,6 +41,11 @@ public enum AEADAlgorithm {
|
||||||
this.tagLength = tagLength;
|
this.tagLength = tagLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ID of the AEAD algorithm.
|
||||||
|
*
|
||||||
|
* @return algorithm ID
|
||||||
|
*/
|
||||||
public int getAlgorithmId() {
|
public int getAlgorithmId() {
|
||||||
return algorithmId;
|
return algorithmId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,31 @@ import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic {@link SecretKeyRingProtector} implementation that respects the users {@link KeyRingProtectionSettings} when
|
||||||
|
* encrypting keys.
|
||||||
|
*/
|
||||||
public class BaseSecretKeyRingProtector implements SecretKeyRingProtector {
|
public class BaseSecretKeyRingProtector implements SecretKeyRingProtector {
|
||||||
|
|
||||||
private final SecretKeyPassphraseProvider passphraseProvider;
|
private final SecretKeyPassphraseProvider passphraseProvider;
|
||||||
private final KeyRingProtectionSettings protectionSettings;
|
private final KeyRingProtectionSettings protectionSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that uses the given {@link SecretKeyPassphraseProvider} to retrieve passphrases and PGPainless'
|
||||||
|
* default {@link KeyRingProtectionSettings}.
|
||||||
|
*
|
||||||
|
* @param passphraseProvider provider for passphrases
|
||||||
|
*/
|
||||||
public BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider) {
|
public BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider) {
|
||||||
this(passphraseProvider, KeyRingProtectionSettings.secureDefaultSettings());
|
this(passphraseProvider, KeyRingProtectionSettings.secureDefaultSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that uses the given {@link SecretKeyPassphraseProvider} and {@link KeyRingProtectionSettings}.
|
||||||
|
*
|
||||||
|
* @param passphraseProvider provider for passphrases
|
||||||
|
* @param protectionSettings protection settings
|
||||||
|
*/
|
||||||
public BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider, KeyRingProtectionSettings protectionSettings) {
|
public BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider, KeyRingProtectionSettings protectionSettings) {
|
||||||
this.passphraseProvider = passphraseProvider;
|
this.passphraseProvider = passphraseProvider;
|
||||||
this.protectionSettings = protectionSettings;
|
this.protectionSettings = protectionSettings;
|
||||||
|
|
|
@ -29,6 +29,12 @@ import org.pgpainless.util.Passphrase;
|
||||||
*/
|
*/
|
||||||
public interface SecretKeyRingProtector {
|
public interface SecretKeyRingProtector {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true, if the protector has a passphrase for the key with the given key-id.
|
||||||
|
*
|
||||||
|
* @param keyId key id
|
||||||
|
* @return true if it has a passphrase, false otherwise
|
||||||
|
*/
|
||||||
boolean hasPassphraseFor(Long keyId);
|
boolean hasPassphraseFor(Long keyId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,15 +33,33 @@ import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.decryption_verification.OpenPgpInputStream;
|
import org.pgpainless.decryption_verification.OpenPgpInputStream;
|
||||||
import org.pgpainless.key.OpenPgpFingerprint;
|
import org.pgpainless.key.OpenPgpFingerprint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for dealing with ASCII armored OpenPGP data.
|
||||||
|
*/
|
||||||
public final class ArmorUtils {
|
public final class ArmorUtils {
|
||||||
|
|
||||||
// MessageIDs are 32 printable characters
|
// MessageIDs are 32 printable characters
|
||||||
private static final Pattern PATTERN_MESSAGE_ID = Pattern.compile("^\\S{32}$");
|
private static final Pattern PATTERN_MESSAGE_ID = Pattern.compile("^\\S{32}$");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant armor key for comments.
|
||||||
|
*/
|
||||||
public static final String HEADER_COMMENT = "Comment";
|
public static final String HEADER_COMMENT = "Comment";
|
||||||
|
/**
|
||||||
|
* Constant armor key for program versions.
|
||||||
|
*/
|
||||||
public static final String HEADER_VERSION = "Version";
|
public static final String HEADER_VERSION = "Version";
|
||||||
|
/**
|
||||||
|
* Constant armor key for message IDs. Useful for split messages.
|
||||||
|
*/
|
||||||
public static final String HEADER_MESSAGEID = "MessageID";
|
public static final String HEADER_MESSAGEID = "MessageID";
|
||||||
|
/**
|
||||||
|
* Constant armor key for used hash algorithms in clearsigned messages.
|
||||||
|
*/
|
||||||
public static final String HEADER_HASH = "Hash";
|
public static final String HEADER_HASH = "Hash";
|
||||||
|
/**
|
||||||
|
* Constant armor key for message character sets.
|
||||||
|
*/
|
||||||
public static final String HEADER_CHARSET = "Charset";
|
public static final String HEADER_CHARSET = "Charset";
|
||||||
|
|
||||||
private ArmorUtils() {
|
private ArmorUtils() {
|
||||||
|
|
|
@ -9,12 +9,23 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory class for instantiating preconfigured {@link ArmoredInputStream ArmoredInputStreams}.
|
||||||
|
* {@link #get(InputStream)} will return an {@link ArmoredInputStream} that is set up to properly detect CRC errors.
|
||||||
|
*/
|
||||||
public final class ArmoredInputStreamFactory {
|
public final class ArmoredInputStreamFactory {
|
||||||
|
|
||||||
private ArmoredInputStreamFactory() {
|
private ArmoredInputStreamFactory() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance of {@link ArmoredInputStream} which will detect CRC errors.
|
||||||
|
*
|
||||||
|
* @param inputStream input stream
|
||||||
|
* @return armored input stream
|
||||||
|
* @throws IOException in case of an IO error
|
||||||
|
*/
|
||||||
public static ArmoredInputStream get(InputStream inputStream) throws IOException {
|
public static ArmoredInputStream get(InputStream inputStream) throws IOException {
|
||||||
if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
|
if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
|
||||||
return (ArmoredInputStream) inputStream;
|
return (ArmoredInputStream) inputStream;
|
||||||
|
|
|
@ -15,6 +15,9 @@ import org.pgpainless.encryption_signing.ProducerOptions;
|
||||||
*/
|
*/
|
||||||
public final class ArmoredOutputStreamFactory {
|
public final class ArmoredOutputStreamFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the program.
|
||||||
|
*/
|
||||||
public static final String PGPAINLESS = "PGPainless";
|
public static final String PGPAINLESS = "PGPainless";
|
||||||
private static String version = PGPAINLESS;
|
private static String version = PGPAINLESS;
|
||||||
private static String[] comment = new String[0];
|
private static String[] comment = new String[0];
|
||||||
|
@ -42,6 +45,13 @@ public final class ArmoredOutputStreamFactory {
|
||||||
return armoredOutputStream;
|
return armoredOutputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance of the {@link ArmoredOutputStream} which might have pre-populated armor headers.
|
||||||
|
*
|
||||||
|
* @param outputStream output stream
|
||||||
|
* @param options options
|
||||||
|
* @return armored output stream
|
||||||
|
*/
|
||||||
public static ArmoredOutputStream get(OutputStream outputStream, ProducerOptions options) {
|
public static ArmoredOutputStream get(OutputStream outputStream, ProducerOptions options) {
|
||||||
if (options.isHideArmorHeaders()) {
|
if (options.isHideArmorHeaders()) {
|
||||||
ArmoredOutputStream armorOut = new ArmoredOutputStream(outputStream);
|
ArmoredOutputStream armorOut = new ArmoredOutputStream(outputStream);
|
||||||
|
|
Loading…
Reference in a new issue