• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pgpainless / pgpainless / #1062

24 Sep 2025 06:08PM UTC coverage: 85.016% (-1.7%) from 86.735%
#1062

push

github

vanitasvitae
Merge branch 'v6' into release/2.0

2576 of 3097 new or added lines in 141 files covered. (83.18%)

148 existing lines in 33 files now uncovered.

6712 of 7895 relevant lines covered (85.02%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/pgpainless-core/src/main/kotlin/org/pgpainless/algorithm/PublicKeyAlgorithm.kt
1
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
2
//
3
// SPDX-License-Identifier: Apache-2.0
4

5
package org.pgpainless.algorithm
6

7
import org.bouncycastle.bcpg.PublicKeyUtils
8

9
/**
10
 * Enumeration of public key algorithms as defined in RFC4880, RFC9580, Persistent Symmetric Keys.
11
 *
12
 * @see [RFC4880: Public-Key Algorithms](https://tools.ietf.org/html/rfc4880#section-9.1)
13
 * @see
14
 *   [RFC9580: Public-Key Algorithms](https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms)
15
 * @see
16
 *   [Persistent Symmetric Keys in OpenPGP](https://www.ietf.org/archive/id/draft-ietf-openpgp-persistent-symmetric-keys-01.html#name-persistent-symmetric-key-al)
17
 */
18
enum class PublicKeyAlgorithm(val algorithmId: Int) {
1✔
19

20
    // RFC4880
21

22
    /** RSA capable of encryption and signatures. */
23
    RSA_GENERAL(1),
1✔
24

25
    /**
26
     * RSA with usage encryption.
27
     *
28
     * @deprecated see [Deprecation notice](https://tools.ietf.org/html/rfc4880#section-13.5)
29
     */
30
    @Deprecated("RSA_ENCRYPT is deprecated in favor of RSA_GENERAL", ReplaceWith("RSA_GENERAL"))
1✔
31
    RSA_ENCRYPT(2),
1✔
32

33
    /**
34
     * RSA with usage of creating signatures.
35
     *
36
     * @deprecated see [Deprecation notice](https://tools.ietf.org/html/rfc4880#section-13.5)
37
     */
38
    @Deprecated("RSA_SIGN is deprecated in favor of RSA_GENERAL", ReplaceWith("RSA_GENERAL"))
1✔
39
    RSA_SIGN(3),
1✔
40

41
    /** ElGamal with usage encryption. */
42
    ELGAMAL_ENCRYPT(16),
1✔
43

44
    /** Digital Signature Algorithm. */
45
    DSA(17),
1✔
46

47
    /** Elliptic Curve Diffie-Hellman. */
48
    ECDH(18),
1✔
49

50
    /** Elliptic Curve Digital Signature Algorithm. */
51
    ECDSA(19),
1✔
52

53
    /**
54
     * ElGamal General.
55
     *
56
     * @deprecated see [Deprecation notice](https://tools.ietf.org/html/rfc4880#section-13.8)
57
     */
58
    @Deprecated("ElGamal is deprecated") ELGAMAL_GENERAL(20),
1✔
59

60
    /** Diffie-Hellman key exchange algorithm. */
61
    DIFFIE_HELLMAN(21),
1✔
62

63
    /** Digital Signature Algorithm based on twisted Edwards Curves. */
64
    EDDSA_LEGACY(22),
1✔
65

66
    // RFC9580
67

68
    /** X25519 encryption algorithm. */
69
    X25519(25),
1✔
70

71
    /** X448 encryption algorithm. */
72
    X448(26),
1✔
73

74
    /** Ed25519 signature algorithm. */
75
    ED25519(27),
1✔
76

77
    /** Ed448 signature algorithm. */
78
    ED448(28),
1✔
79

80
    // Persistent Symmetric Keys in OpenPGP
81

82
    /**
83
     * AEAD can be used as a persistent key symmetric encryption algorithm for message encryption.
84
     *
85
     * @see
86
     *   [Persistent Symmetric Keys in OpenPGP](https://datatracker.ietf.org/doc/draft-ietf-openpgp-persistent-symmetric-keys/)
87
     */
88
    AEAD(128) {
1✔
NEW
89
        override val signingCapable = false
×
90
        override val encryptionCapable = true
1✔
91
    },
92

93
    /**
94
     * HMAC can be used as a persistent key symmetric signing algorithm for message signing.
95
     *
96
     * @see
97
     *   [Persistent Symmetric Keys in OpenPGP](https://datatracker.ietf.org/doc/draft-ietf-openpgp-persistent-symmetric-keys/)
98
     */
99
    HMAC(129) {
1✔
100
        override val signingCapable = true
1✔
NEW
101
        override val encryptionCapable = false
×
102
    };
103

104
    open val signingCapable: Boolean = PublicKeyUtils.isSigningAlgorithm(algorithmId)
1✔
105
    open val encryptionCapable: Boolean = PublicKeyUtils.isEncryptionAlgorithm(algorithmId)
1✔
106

107
    fun isSigningCapable(): Boolean = signingCapable
1✔
108

109
    fun isEncryptionCapable(): Boolean = encryptionCapable
1✔
110

111
    companion object {
112
        @JvmStatic
113
        fun fromId(id: Int): PublicKeyAlgorithm? {
114
            return values().firstOrNull { it.algorithmId == id }
1✔
115
        }
116

117
        @JvmStatic
118
        fun requireFromId(id: Int): PublicKeyAlgorithm {
119
            return fromId(id)
1✔
120
                ?: throw NoSuchElementException("No PublicKeyAlgorithm found for id $id")
×
121
        }
122
    }
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc