Package org.pgpainless.key.protection.passphrase_provider

# Class MapBasedPassphraseProvider

java.lang.Object
org.pgpainless.key.protection.passphrase_provider.MapBasedPassphraseProvider

All Implemented Interfaces:
  `SecretKeyPassphraseProvider`

public class MapBasedPassphraseProvider extends Object implements SecretKeyPassphraseProvider
Implementation of the `SecretKeyPassphraseProvider` that holds a map of different `passphrases`. It will return the right passphrase depending on the key-id. Note: This provider might return null! TODO: Make this null-safe and throw an exception instead?

## Constructor Summary

Constructors
Constructor
Description
`MapBasedPassphraseProvider(Map<Long,Passphrase> passphraseMap)`
Create a new map based passphrase provider.

## Method Summary

Modifier and Type
Method
Description
`Passphrase`
`getPassphraseFor(Long keyId)`
Return a passphrase for the given key.
`boolean`
`hasPassphrase(Long keyId)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider

`getPassphraseFor`

## Constructor Details

### MapBasedPassphraseProvider

public MapBasedPassphraseProvider(Map<Long,Passphrase> passphraseMap)
Create a new map based passphrase provider.

Parameters:
  `passphraseMap` - map of key-ids and passphrases

## Method Details

### getPassphraseFor

@Nullable public Passphrase getPassphraseFor(Long keyId)
Description copied from interface: `SecretKeyPassphraseProvider`
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.

Specified by:
  `getPassphraseFor` in interface `SecretKeyPassphraseProvider`
Parameters:
  `keyId` - if of the secret key
Returns:
  passphrase or null, if no passphrase record has been found.

### hasPassphrase

public boolean hasPassphrase(Long keyId)

Specified by:
  `hasPassphrase` in interface `SecretKeyPassphraseProvider`