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

pgpainless / sop-java / #65

12 Jan 2026 11:37AM UTC coverage: 57.95% (-0.3%) from 58.291%
#65

push

other

vanitasvitae
Add comments

2103 of 3629 relevant lines covered (57.95%)

0.58 hits per line

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

52.94
/sop-java/src/main/kotlin/sop/operation/ChangeKeyPassword.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.InputStream
8
import sop.Ready
9
import sop.exception.SOPGPException
10
import sop.exception.SOPGPException.BadData
11
import sop.exception.SOPGPException.KeyIsProtected
12
import sop.exception.SOPGPException.PasswordNotHumanReadable
13
import sop.util.UTF8Util
14

15
/** Interface for changing key passwords. */
16
interface ChangeKeyPassword {
17

18
    /**
19
     * Disable ASCII armoring of the output.
20
     *
21
     * @return builder instance
22
     */
23
    @Throws(SOPGPException.UnsupportedOption::class) fun noArmor(): ChangeKeyPassword
24

25
    /**
26
     * Provide a passphrase to unlock the secret key. This method can be provided multiple times to
27
     * provide separate passphrases that are tried as a means to unlock any secret key material
28
     * encountered.
29
     *
30
     * @param oldPassphrase old passphrase
31
     * @return builder instance
32
     */
33
    fun oldKeyPassphrase(oldPassphrase: CharArray): ChangeKeyPassword =
×
34
        oldKeyPassphrase(oldPassphrase.concatToString())
×
35

36
    /**
37
     * Provide a passphrase to unlock the secret key. This method can be provided multiple times to
38
     * provide separate passphrases that are tried as a means to unlock any secret key material
39
     * encountered.
40
     *
41
     * @param oldPassphrase old passphrase
42
     * @return builder instance
43
     */
44
    fun oldKeyPassphrase(oldPassphrase: String): ChangeKeyPassword
45

46
    /**
47
     * Provide a passphrase to unlock the secret key. This method can be provided multiple times to
48
     * provide separate passphrases that are tried as a means to unlock any secret key material
49
     * encountered.
50
     *
51
     * @param oldPassphrase old passphrase
52
     * @return builder instance
53
     * @throws PasswordNotHumanReadable if the old key passphrase is not human-readable
54
     */
55
    @Throws(PasswordNotHumanReadable::class)
56
    fun oldKeyPassphrase(oldPassphrase: ByteArray): ChangeKeyPassword =
×
57
        try {
1✔
58
            oldKeyPassphrase(UTF8Util.decodeUTF8(oldPassphrase))
×
59
        } catch (e: CharacterCodingException) {
1✔
60
            throw PasswordNotHumanReadable("Password MUST be a valid UTF8 string.")
1✔
61
        }
×
62

63
    /**
64
     * Provide a passphrase to re-lock the secret key with. This method can only be used once, and
65
     * all key material encountered will be encrypted with the given passphrase. If this method is
66
     * not called, the key material will not be protected.
67
     *
68
     * @param newPassphrase new passphrase
69
     * @return builder instance
70
     */
71
    fun newKeyPassphrase(newPassphrase: CharArray): ChangeKeyPassword =
×
72
        newKeyPassphrase(newPassphrase.concatToString())
×
73

74
    /**
75
     * Provide a passphrase to re-lock the secret key with. This method can only be used once, and
76
     * all key material encountered will be encrypted with the given passphrase. If this method is
77
     * not called, the key material will not be protected.
78
     *
79
     * @param newPassphrase new passphrase
80
     * @return builder instance
81
     */
82
    fun newKeyPassphrase(newPassphrase: String): ChangeKeyPassword
83

84
    /**
85
     * Provide a passphrase to re-lock the secret key with. This method can only be used once, and
86
     * all key material encountered will be encrypted with the given passphrase. If this method is
87
     * not called, the key material will not be protected.
88
     *
89
     * @param newPassphrase new passphrase
90
     * @return builder instance
91
     * @throws PasswordNotHumanReadable if the passphrase is not human-readable
92
     */
93
    @Throws(PasswordNotHumanReadable::class)
94
    fun newKeyPassphrase(newPassphrase: ByteArray): ChangeKeyPassword =
×
95
        try {
1✔
96
            newKeyPassphrase(UTF8Util.decodeUTF8(newPassphrase))
1✔
97
        } catch (e: CharacterCodingException) {
1✔
98
            throw PasswordNotHumanReadable("Password MUST be a valid UTF8 string.")
1✔
99
        }
1✔
100

101
    /**
102
     * Provide the key material.
103
     *
104
     * @param keys input stream of secret key material
105
     * @return ready
106
     * @throws KeyIsProtected if any (sub-) key encountered cannot be unlocked.
107
     * @throws BadData if the key material is malformed
108
     */
109
    @Throws(KeyIsProtected::class, BadData::class)
110
    fun keys(keys: ByteArray): Ready = keys(keys.inputStream())
1✔
111

112
    /**
113
     * Provide the key material.
114
     *
115
     * @param keys input stream of secret key material
116
     * @return ready
117
     * @throws KeyIsProtected if any (sub-) key encountered cannot be unlocked.
118
     * @throws BadData if the key material is malformed
119
     */
120
    @Throws(KeyIsProtected::class, BadData::class) fun keys(keys: InputStream): Ready
121
}
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