001// SPDX-FileCopyrightText: 2020 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.pgpainless.util.Passphrase; 010 011/** 012 * Implementation of the {@link SecretKeyPassphraseProvider} that holds a single {@link Passphrase}. 013 */ 014public class SolitaryPassphraseProvider implements SecretKeyPassphraseProvider { 015 016 private final Passphrase passphrase; 017 018 public SolitaryPassphraseProvider(Passphrase passphrase) { 019 this.passphrase = passphrase; 020 } 021 022 @Nullable 023 @Override 024 public Passphrase getPassphraseFor(Long keyId) { 025 // always return the same passphrase. 026 return passphrase; 027 } 028 029 @Override 030 public boolean hasPassphrase(Long keyId) { 031 return true; 032 } 033}