001// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org> 002// 003// SPDX-License-Identifier: Apache-2.0 004 005package org.pgpainless.key.protection.passphrase_provider; 006 007import javax.annotation.Nullable; 008 009import org.bouncycastle.openpgp.PGPSecretKey; 010import org.pgpainless.util.Passphrase; 011 012/** 013 * Interface to allow the user to provide a {@link Passphrase} for an encrypted OpenPGP secret key. 014 */ 015public interface SecretKeyPassphraseProvider { 016 017 /** 018 * Return a passphrase for the given secret key. 019 * If no record is found, return null. 020 * Note: In case of an unprotected secret key, this method must may not return null, but a {@link Passphrase} with 021 * a content of null. 022 * 023 * @param secretKey secret key 024 * @return passphrase or null, if no passphrase record is found. 025 */ 026 @Nullable default Passphrase getPassphraseFor(PGPSecretKey secretKey) { 027 return getPassphraseFor(secretKey.getKeyID()); 028 } 029 /** 030 * Return a passphrase for the given key. If no record has been found, return null. 031 * Note: In case of an unprotected secret key, this method must may not return null, but a {@link Passphrase} with 032 * a content of null. 033 * 034 * @param keyId if of the secret key 035 * @return passphrase or null, if no passphrase record has been found. 036 */ 037 @Nullable Passphrase getPassphraseFor(Long keyId); 038 039 boolean hasPassphrase(Long keyId); 040}