• 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

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.BadData
10
import sop.exception.SOPGPException.KeyIsProtected
11
import sop.exception.SOPGPException.PasswordNotHumanReadable
12
import sop.util.UTF8Util
13

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

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

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

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

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

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

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

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

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

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