1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Add javadoc to enums

This commit is contained in:
Paul Schaub 2021-04-25 13:28:33 +02:00
parent 2c4a3fca6a
commit 7916bf77d1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
9 changed files with 253 additions and 2 deletions

View file

@ -20,6 +20,11 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.bcpg.CompressionAlgorithmTags; import org.bouncycastle.bcpg.CompressionAlgorithmTags;
/**
* Enumeration of possible compression algorithms.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.3">RFC4880: Compression Algorithm Tags</a>
*/
public enum CompressionAlgorithm { public enum CompressionAlgorithm {
UNCOMPRESSED (CompressionAlgorithmTags.UNCOMPRESSED), UNCOMPRESSED (CompressionAlgorithmTags.UNCOMPRESSED),
@ -36,6 +41,13 @@ public enum CompressionAlgorithm {
} }
} }
/**
* Return the {@link CompressionAlgorithm} value that corresponds to the provided numerical id.
* If an invalid id is provided, null is returned.
*
* @param id id
* @return compression algorithm
*/
public static CompressionAlgorithm fromId(int id) { public static CompressionAlgorithm fromId(int id) {
return MAP.get(id); return MAP.get(id);
} }
@ -46,6 +58,10 @@ public enum CompressionAlgorithm {
this.algorithmId = id; this.algorithmId = id;
} }
/**
* Return the numerical algorithm tag corresponding to this compression algorithm.
* @return id
*/
public int getAlgorithmId() { public int getAlgorithmId() {
return algorithmId; return algorithmId;
} }

View file

@ -20,6 +20,11 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.bcpg.sig.Features; import org.bouncycastle.bcpg.sig.Features;
/**
* An enumeration of features that may be set in the {@link Features} subpacket.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-5.2.3.24">RFC4880: Features</a>
*/
public enum Feature { public enum Feature {
/** /**

View file

@ -20,8 +20,13 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.bcpg.HashAlgorithmTags; import org.bouncycastle.bcpg.HashAlgorithmTags;
/**
* An enumeration of different hashing algorithms.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.4">RFC4880: Hash Algorithms</a>
*/
public enum HashAlgorithm { public enum HashAlgorithm {
@Deprecated
MD5 (HashAlgorithmTags.MD5), MD5 (HashAlgorithmTags.MD5),
SHA1 (HashAlgorithmTags.SHA1), SHA1 (HashAlgorithmTags.SHA1),
RIPEMD160 (HashAlgorithmTags.RIPEMD160), RIPEMD160 (HashAlgorithmTags.RIPEMD160),
@ -43,6 +48,13 @@ public enum HashAlgorithm {
} }
} }
/**
* Return the {@link HashAlgorithm} value that corresponds to the provided algorithm id.
* If an invalid algorithm id was provided, null is returned.
*
* @param id numeric id
* @return enum value
*/
public static HashAlgorithm fromId(int id) { public static HashAlgorithm fromId(int id) {
return MAP.get(id); return MAP.get(id);
} }
@ -53,6 +65,11 @@ public enum HashAlgorithm {
this.algorithmId = id; this.algorithmId = id;
} }
/**
* Return the numeric algorithm id of the hash algorithm.
*
* @return numeric id
*/
public int getAlgorithmId() { public int getAlgorithmId() {
return algorithmId; return algorithmId;
} }

View file

@ -20,14 +20,47 @@ import java.util.List;
import org.bouncycastle.bcpg.sig.KeyFlags; import org.bouncycastle.bcpg.sig.KeyFlags;
/**
* Enumeration of different key flags.
* Key flags denote different capabilities of a key pair.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-5.2.3.21">RFC4880: Key Flags</a>
*/
public enum KeyFlag { public enum KeyFlag {
/**
* This key may be used to certify other keys.
*/
CERTIFY_OTHER (KeyFlags.CERTIFY_OTHER), CERTIFY_OTHER (KeyFlags.CERTIFY_OTHER),
/**
* This key may be used to sign data.
*/
SIGN_DATA (KeyFlags.SIGN_DATA), SIGN_DATA (KeyFlags.SIGN_DATA),
/**
* This key may be used to encrypt communications.
*/
ENCRYPT_COMMS (KeyFlags.ENCRYPT_COMMS), ENCRYPT_COMMS (KeyFlags.ENCRYPT_COMMS),
/**
* This key may be used to encrypt storage.
*/
ENCRYPT_STORAGE(KeyFlags.ENCRYPT_STORAGE), ENCRYPT_STORAGE(KeyFlags.ENCRYPT_STORAGE),
/**
* The private component of this key may have been split by a secret-sharing mechanism.
*/
SPLIT (KeyFlags.SPLIT), SPLIT (KeyFlags.SPLIT),
/**
* This key may be used for authentication.
*/
AUTHENTICATION (KeyFlags.AUTHENTICATION), AUTHENTICATION (KeyFlags.AUTHENTICATION),
/**
* The private component of this key may be in the possession of more than one person.
*/
SHARED (KeyFlags.SHARED), SHARED (KeyFlags.SHARED),
; ;
@ -37,10 +70,21 @@ public enum KeyFlag {
this.flag = flag; this.flag = flag;
} }
/**
* Return the numeric id of the {@link KeyFlag}.
*
* @return numeric id
*/
public int getFlag() { public int getFlag() {
return flag; return flag;
} }
/**
* Convert a bitmask into a list of {@link KeyFlag KeyFlags}.
*
* @param bitmask bitmask
* @return list of key flags encoded by the bitmask
*/
public static List<KeyFlag> fromBitmask(int bitmask) { public static List<KeyFlag> fromBitmask(int bitmask) {
List<KeyFlag> flags = new ArrayList<>(); List<KeyFlag> flags = new ArrayList<>();
for (KeyFlag f : KeyFlag.values()) { for (KeyFlag f : KeyFlag.values()) {
@ -51,6 +95,12 @@ public enum KeyFlag {
return flags; return flags;
} }
/**
* Encode a list of {@link KeyFlag KeyFlags} into a bitmask.
*
* @param flags list of flags
* @return bitmask
*/
public static int toBitmask(KeyFlag... flags) { public static int toBitmask(KeyFlag... flags) {
int mask = 0; int mask = 0;
for (KeyFlag f : flags) { for (KeyFlag f : flags) {
@ -59,6 +109,14 @@ public enum KeyFlag {
return mask; return mask;
} }
/**
* Return true if the provided bitmask has the bit for the provided flag set.
* Return false if the mask does not contain the flag.
*
* @param mask bitmask
* @param flag flag to be tested for
* @return true if flag is set, false otherwise
*/
public static boolean hasKeyFlag(int mask, KeyFlag flag) { public static boolean hasKeyFlag(int mask, KeyFlag flag) {
return (mask & flag.getFlag()) == flag.getFlag(); return (mask & flag.getFlag()) == flag.getFlag();
} }

View file

@ -20,6 +20,11 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
/**
* Enumeration of public key algorithms as defined in RFC4880.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.1">RFC4880: Public-Key Algorithms</a>
*/
public enum PublicKeyAlgorithm { public enum PublicKeyAlgorithm {
/** /**
@ -32,6 +37,7 @@ public enum PublicKeyAlgorithm {
* *
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5 * @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5
*/ */
@Deprecated
RSA_ENCRYPT (PublicKeyAlgorithmTags.RSA_ENCRYPT), RSA_ENCRYPT (PublicKeyAlgorithmTags.RSA_ENCRYPT),
/** /**
@ -39,6 +45,7 @@ public enum PublicKeyAlgorithm {
* *
* @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5 * @deprecated see https://tools.ietf.org/html/rfc4880#section-13.5
*/ */
@Deprecated
RSA_SIGN (PublicKeyAlgorithmTags.RSA_SIGN), RSA_SIGN (PublicKeyAlgorithmTags.RSA_SIGN),
/** /**
@ -55,6 +62,7 @@ public enum PublicKeyAlgorithm {
* EC is deprecated. * EC is deprecated.
* @deprecated use {@link #ECDH} instead. * @deprecated use {@link #ECDH} instead.
*/ */
@Deprecated
EC (PublicKeyAlgorithmTags.EC), EC (PublicKeyAlgorithmTags.EC),
/** /**
@ -94,6 +102,13 @@ public enum PublicKeyAlgorithm {
} }
} }
/**
* Return the {@link PublicKeyAlgorithm} that corresponds to the provided algorithm id.
* If an invalid id is provided, null is returned.
*
* @param id numeric algorithm id
* @return algorithm
*/
public static PublicKeyAlgorithm fromId(int id) { public static PublicKeyAlgorithm fromId(int id) {
return MAP.get(id); return MAP.get(id);
} }
@ -104,6 +119,11 @@ public enum PublicKeyAlgorithm {
this.algorithmId = algorithmId; this.algorithmId = algorithmId;
} }
/**
* Return the numeric identifier of the public key algorithm.
*
* @return id
*/
public int getAlgorithmId() { public int getAlgorithmId() {
return algorithmId; return algorithmId;
} }

View file

@ -49,6 +49,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/**
* Enumeration of possible subpackets that might be found in the hashed and unhashed area of an OpenPGP signature.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-5.2.3.1">RFC4880: Signature Subpacket Specification</a>
*/
public enum SignatureSubpacket { public enum SignatureSubpacket {
/** /**
@ -408,10 +413,20 @@ public enum SignatureSubpacket {
this.code = code; this.code = code;
} }
/**
* Return the numerical identifier of the {@link SignatureSubpacket}.
* @return id
*/
public int getCode() { public int getCode() {
return code; return code;
} }
/**
* Return the {@link SignatureSubpacket} that corresponds to the provided id.
*
* @param code id
* @return signature subpacket
*/
public static SignatureSubpacket fromCode(int code) { public static SignatureSubpacket fromCode(int code) {
SignatureSubpacket tag = MAP.get(code); SignatureSubpacket tag = MAP.get(code);
if (tag == null) { if (tag == null) {
@ -420,6 +435,12 @@ public enum SignatureSubpacket {
return tag; return tag;
} }
/**
* Convert an array of signature subpacket tags into a list of {@link SignatureSubpacket SignatureSubpackets}.
*
* @param codes array of codes
* @return list of subpackets
*/
public static List<SignatureSubpacket> fromCodes(int[] codes) { public static List<SignatureSubpacket> fromCodes(int[] codes) {
List<SignatureSubpacket> tags = new ArrayList<>(); List<SignatureSubpacket> tags = new ArrayList<>();
for (int code : codes) { for (int code : codes) {

View file

@ -173,6 +173,12 @@ public enum SignatureType {
} }
} }
/**
* Convert a numerical id into a {@link SignatureType}.
*
* @param code numeric id
* @return signature type enum
*/
public static SignatureType valueOf(int code) { public static SignatureType valueOf(int code) {
SignatureType type = map.get(code); SignatureType type = map.get(code);
if (type != null) { if (type != null) {
@ -187,6 +193,11 @@ public enum SignatureType {
this.code = code; this.code = code;
} }
/**
* Return the numeric id of the signature type enum.
*
* @return numeric id
*/
public int getCode() { public int getCode() {
return code; return code;
} }

View file

@ -21,14 +21,33 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.openpgp.PGPLiteralData; import org.bouncycastle.openpgp.PGPLiteralData;
/** /**
* Encoding of the stream. * Enumeration of possible encoding formats of the content of the literal data packet.
* *
* @see <a href="https://tools.ietf.org/html/rfc4880#section-5.9">RFC4880: Literal Data Packet</a> * @see <a href="https://tools.ietf.org/html/rfc4880#section-5.9">RFC4880: Literal Data Packet</a>
*/ */
public enum StreamEncoding { public enum StreamEncoding {
/**
* The Literal packet contains binary data.
*/
BINARY(PGPLiteralData.BINARY), BINARY(PGPLiteralData.BINARY),
/**
* The Literal packet contains text data, and thus may need line ends converted to local form, or other
* text-mode changes.
*/
TEXT(PGPLiteralData.TEXT), TEXT(PGPLiteralData.TEXT),
/**
* Indication that the implementation believes that the literal data contains UTF-8 text.
*/
UTF8(PGPLiteralData.UTF8), UTF8(PGPLiteralData.UTF8),
/**
* Early versions of PGP also defined a value of 'l' as a 'local' mode for machine-local conversions.
* RFC 1991 [RFC1991] incorrectly stated this local mode flag as '1' (ASCII numeral one).
* Both of these local modes are deprecated.
*/
@Deprecated @Deprecated
LOCAL('l'), LOCAL('l'),
; ;
@ -40,6 +59,7 @@ public enum StreamEncoding {
for (StreamEncoding f : StreamEncoding.values()) { for (StreamEncoding f : StreamEncoding.values()) {
MAP.put(f.code, f); MAP.put(f.code, f);
} }
// RFC 1991 [RFC1991] incorrectly stated local mode flag as '1', see doc of LOCAL.
MAP.put('1', LOCAL); MAP.put('1', LOCAL);
} }
@ -47,10 +67,21 @@ public enum StreamEncoding {
this.code = code; this.code = code;
} }
/**
* Return the code identifier of the encoding.
*
* @return identifier
*/
public char getCode() { public char getCode() {
return code; return code;
} }
/**
* Return the {@link StreamEncoding} corresponding to the provided code identifier.
*
* @param code identifier
* @return encoding enum
*/
public static StreamEncoding fromCode(int code) { public static StreamEncoding fromCode(int code) {
return MAP.get((char) code); return MAP.get((char) code);
} }

View file

@ -20,25 +20,85 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
/**
* Enumeration of possible symmetric encryption algorithms.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.2">RFC4880: Symmetric-Key Algorithms</a>
*/
public enum SymmetricKeyAlgorithm { public enum SymmetricKeyAlgorithm {
/**
* Plaintext or unencrypted data.
*/
NULL (SymmetricKeyAlgorithmTags.NULL), NULL (SymmetricKeyAlgorithmTags.NULL),
/** /**
* IDEA is deprecated. * IDEA is deprecated.
* @deprecated use a different algorithm. * @deprecated use a different algorithm.
*/ */
@Deprecated
IDEA (SymmetricKeyAlgorithmTags.IDEA), IDEA (SymmetricKeyAlgorithmTags.IDEA),
/**
* TripleDES (DES-EDE - 168 bit key derived from 192).
*/
TRIPLE_DES (SymmetricKeyAlgorithmTags.TRIPLE_DES), TRIPLE_DES (SymmetricKeyAlgorithmTags.TRIPLE_DES),
/**
* CAST5 (128 bit key, as per RFC2144).
*/
CAST5 (SymmetricKeyAlgorithmTags.CAST5), CAST5 (SymmetricKeyAlgorithmTags.CAST5),
/**
* Blowfish (128 bit key, 16 rounds).
*/
BLOWFISH (SymmetricKeyAlgorithmTags.BLOWFISH), BLOWFISH (SymmetricKeyAlgorithmTags.BLOWFISH),
/**
* Reserved in RFC4880.
* SAFER-SK128 (13 rounds)
*/
SAFER (SymmetricKeyAlgorithmTags.SAFER), SAFER (SymmetricKeyAlgorithmTags.SAFER),
/**
* Reserved in RFC4880.
* Reserved for DES/SK
*/
DES (SymmetricKeyAlgorithmTags.DES), DES (SymmetricKeyAlgorithmTags.DES),
/**
* AES with 128-bit key.
*/
AES_128 (SymmetricKeyAlgorithmTags.AES_128), AES_128 (SymmetricKeyAlgorithmTags.AES_128),
/**
* AES with 192-bit key.
*/
AES_192 (SymmetricKeyAlgorithmTags.AES_192), AES_192 (SymmetricKeyAlgorithmTags.AES_192),
/**
* AES with 256-bit key.
*/
AES_256 (SymmetricKeyAlgorithmTags.AES_256), AES_256 (SymmetricKeyAlgorithmTags.AES_256),
/**
* Twofish with 256-bit key.
*/
TWOFISH (SymmetricKeyAlgorithmTags.TWOFISH), TWOFISH (SymmetricKeyAlgorithmTags.TWOFISH),
/**
* Reserved for Camellia with 128-bit key.
*/
CAMELLIA_128 (SymmetricKeyAlgorithmTags.CAMELLIA_128), CAMELLIA_128 (SymmetricKeyAlgorithmTags.CAMELLIA_128),
/**
* Reserved for Camellia with 192-bit key.
*/
CAMELLIA_192 (SymmetricKeyAlgorithmTags.CAMELLIA_192), CAMELLIA_192 (SymmetricKeyAlgorithmTags.CAMELLIA_192),
/**
* Reserved for Camellia with 256-bit key.
*/
CAMELLIA_256 (SymmetricKeyAlgorithmTags.CAMELLIA_256), CAMELLIA_256 (SymmetricKeyAlgorithmTags.CAMELLIA_256),
; ;
@ -50,6 +110,13 @@ public enum SymmetricKeyAlgorithm {
} }
} }
/**
* Return the {@link SymmetricKeyAlgorithm} enum that corresponds to the provided numeric id.
* If an invalid id is provided, null is returned.
*
* @param id numeric algorithm id
* @return symmetric key algorithm enum
*/
public static SymmetricKeyAlgorithm fromId(int id) { public static SymmetricKeyAlgorithm fromId(int id) {
return MAP.get(id); return MAP.get(id);
} }
@ -60,6 +127,11 @@ public enum SymmetricKeyAlgorithm {
this.algorithmId = algorithmId; this.algorithmId = algorithmId;
} }
/**
* Return the numeric algorithm id of the enum.
*
* @return numeric id
*/
public int getAlgorithmId() { public int getAlgorithmId() {
return algorithmId; return algorithmId;
} }