1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-17 00:54:50 +02:00
pgpainless/pgpainless-core/src/main/kotlin/org/pgpainless/key/protection/passphrase_provider/SecretKeyPassphraseProvider.kt
Paul Schaub cd1a3e436c
Kotlin conversion: SecretKeyPassphraseProvider and subclasses
This commit also adds a workaround to build.gradle which enables proper Java interop for
Kotlin interfaces with default implementations
2023-09-04 14:18:44 +02:00

39 lines
1.3 KiB
Kotlin

// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.key.protection.passphrase_provider
import org.bouncycastle.openpgp.PGPSecretKey
import org.pgpainless.util.Passphrase
/**
* Interface to allow the user to provide a [Passphrase] for an encrypted OpenPGP secret key.
*/
interface SecretKeyPassphraseProvider {
/**
* Return a passphrase for the given secret key.
* If no record is found, return null.
* Note: In case of an unprotected secret key, this method must may not return null, but a [Passphrase] with
* a content of null.
*
* @param secretKey secret key
* @return passphrase or null, if no passphrase record is found.
*/
fun getPassphraseFor(secretKey: PGPSecretKey): Passphrase? {
return getPassphraseFor(secretKey.keyID)
}
/**
* Return a passphrase for the given key. If no record has been found, return null.
* Note: In case of an unprotected secret key, this method must may not return null, but a [Passphrase] with
* a content of null.
*
* @param keyId if of the secret key
* @return passphrase or null, if no passphrase record has been found.
*/
fun getPassphraseFor(keyId: Long): Passphrase?
fun hasPassphrase(keyId: Long): Boolean
}