More missing javadoc

This commit is contained in:
Paul Schaub 2023-01-16 20:15:57 +01:00
parent b58861635d
commit a50c2d9714
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
6 changed files with 66 additions and 0 deletions

View File

@ -41,6 +41,11 @@ public enum AEADAlgorithm {
this.tagLength = tagLength;
}
/**
* Return the ID of the AEAD algorithm.
*
* @return algorithm ID
*/
public int getAlgorithmId() {
return algorithmId;
}

View File

@ -13,15 +13,31 @@ import org.pgpainless.util.Passphrase;
import javax.annotation.Nullable;
/**
* Basic {@link SecretKeyRingProtector} implementation that respects the users {@link KeyRingProtectionSettings} when
* encrypting keys.
*/
public class BaseSecretKeyRingProtector implements SecretKeyRingProtector {
private final SecretKeyPassphraseProvider passphraseProvider;
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) {
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) {
this.passphraseProvider = passphraseProvider;
this.protectionSettings = protectionSettings;

View File

@ -29,6 +29,12 @@ import org.pgpainless.util.Passphrase;
*/
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);
/**

View File

@ -33,15 +33,33 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.decryption_verification.OpenPgpInputStream;
import org.pgpainless.key.OpenPgpFingerprint;
/**
* Utility class for dealing with ASCII armored OpenPGP data.
*/
public final class ArmorUtils {
// MessageIDs are 32 printable characters
private static final Pattern PATTERN_MESSAGE_ID = Pattern.compile("^\\S{32}$");
/**
* Constant armor key for comments.
*/
public static final String HEADER_COMMENT = "Comment";
/**
* Constant armor key for program versions.
*/
public static final String HEADER_VERSION = "Version";
/**
* Constant armor key for message IDs. Useful for split messages.
*/
public static final String HEADER_MESSAGEID = "MessageID";
/**
* Constant armor key for used hash algorithms in clearsigned messages.
*/
public static final String HEADER_HASH = "Hash";
/**
* Constant armor key for message character sets.
*/
public static final String HEADER_CHARSET = "Charset";
private ArmorUtils() {

View File

@ -9,12 +9,23 @@ import java.io.InputStream;
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 {
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 {
if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
return (ArmoredInputStream) inputStream;

View File

@ -15,6 +15,9 @@ import org.pgpainless.encryption_signing.ProducerOptions;
*/
public final class ArmoredOutputStreamFactory {
/**
* Name of the program.
*/
public static final String PGPAINLESS = "PGPainless";
private static String version = PGPAINLESS;
private static String[] comment = new String[0];
@ -42,6 +45,13 @@ public final class ArmoredOutputStreamFactory {
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) {
if (options.isHideArmorHeaders()) {
ArmoredOutputStream armorOut = new ArmoredOutputStream(outputStream);