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

pgpainless / sop-java / #54

25 Sep 2025 09:07PM UTC coverage: 58.308% (-0.1%) from 58.411%
#54

push

other

vanitasvitae
Remove unused import

2088 of 3581 relevant lines covered (58.31%)

0.58 hits per line

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

57.14
/sop-java/src/main/kotlin/sop/operation/GenerateKey.kt
1
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
2
//
3
// SPDX-License-Identifier: Apache-2.0
4

5
package sop.operation
6

7
import java.io.IOException
8
import sop.Profile
9
import sop.Ready
10
import sop.exception.SOPGPException.*
11
import sop.util.UTF8Util
12

13
/** Interface for generating OpenPGP keys. */
14
interface GenerateKey {
15

16
    /**
17
     * Disable ASCII armor encoding.
18
     *
19
     * @return builder instance
20
     */
21
    fun noArmor(): GenerateKey
22

23
    /**
24
     * Adds a user-id.
25
     *
26
     * @param userId user-id
27
     * @return builder instance
28
     */
29
    fun userId(userId: String): GenerateKey
30

31
    /**
32
     * Set a password for the key.
33
     *
34
     * @param password password to protect the key
35
     * @return builder instance
36
     * @throws UnsupportedOption if key passwords are not supported
37
     * @throws PasswordNotHumanReadable if the password is not human-readable
38
     */
39
    @Throws(PasswordNotHumanReadable::class, UnsupportedOption::class)
40
    fun withKeyPassword(password: String): GenerateKey
41

42
    /**
43
     * Set a password for the key.
44
     *
45
     * @param password password to protect the key
46
     * @return builder instance
47
     * @throws PasswordNotHumanReadable if the password is not human-readable
48
     * @throws UnsupportedOption if key passwords are not supported
49
     */
50
    @Throws(PasswordNotHumanReadable::class, UnsupportedOption::class)
51
    fun withKeyPassword(password: ByteArray): GenerateKey =
×
52
        try {
1✔
53
            withKeyPassword(UTF8Util.decodeUTF8(password))
1✔
54
        } catch (e: CharacterCodingException) {
×
55
            throw PasswordNotHumanReadable()
1✔
56
        }
1✔
57

58
    /**
59
     * Pass in a profile.
60
     *
61
     * @param profile profile
62
     * @return builder instance
63
     */
64
    fun profile(profile: Profile): GenerateKey = profile(profile.name)
×
65

66
    /**
67
     * Pass in a profile identifier.
68
     *
69
     * @param profile profile identifier
70
     * @return builder instance
71
     */
72
    fun profile(profile: String): GenerateKey
73

74
    /**
75
     * If this options is set, the generated key will not be capable of encryption / decryption.
76
     *
77
     * @return builder instance
78
     */
79
    fun signingOnly(): GenerateKey
80

81
    /**
82
     * Generate the OpenPGP key and return it encoded as an [java.io.InputStream].
83
     *
84
     * @return key
85
     * @throws MissingArg if no user-id was provided
86
     * @throws UnsupportedAsymmetricAlgo if the generated key uses an unsupported asymmetric
87
     *   algorithm
88
     * @throws IOException in case of an IO error
89
     */
90
    @Throws(MissingArg::class, UnsupportedAsymmetricAlgo::class, IOException::class)
91
    fun generate(): Ready
92
}
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