pub fn load_verifier(
input: Option<DirOrFile>,
technology: Technology,
) -> Result<impl VerifierWriter + Debug, Error>
Expand description
Returns an implementation of VerifierWriter
from an input.
Depending on technology
, attempts to load a verifier from file or directory if input
is a
DirOrFile
. Attempts to load a verifier from stdin
if input
is None
.
§Note
Currently only supports Technology::Openpgp
.
§Errors
Returns an error if
- a verifier cannot be loaded from file/directory or stdin,
- an unsupported
technology
is provided.
§Examples
use std::io::Write;
use tempfile::{NamedTempFile, tempdir};
use voa::commands::load_verifier;
// Write a generic OpenPGP certificate to a temporary file.
let cert = r#"-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEaNBDAhYJKwYBBAHaRw8BAQdAzjzrpQ/AEteCmzjd1xTdXGaHV0VKSm4HLy6l
HVcmWT3NH0pvaG4gRG9lIDxqb2huLmRvZUBleGFtcGxlLm9yZz7CmgQQFggAQgUC
aNBDAhYhBEauMg3lOimFWKbyoPtSEBy0DfYKAhsDAh4BBAsJCAcGFQ4KCQwIARYN
JwkCCAIHAgkBCAEHAQIZAQAKCRD7UhActA32CkhIAP9bhoLJeZRCAc+q1kFEkstT
uXBPlzHagF6ghuUfToMmVQD+KaakONKSekglKR4rJxzhleQJ4qsptt1gjXX13QgF
Xwo=
=Pkv9
-----END PGP PUBLIC KEY BLOCK-----"#;
let mut temp_file = NamedTempFile::new()?;
write!(temp_file, "{cert}")?;
let input_path = temp_file.path();
// Load an OpenPGP verifier from file.
let verifier = load_verifier(Some(input_path.try_into()?), "openpgp".parse()?)?;
// Loading a verifier from file for an unknown technology will fail.
assert!(load_verifier(Some(input_path.try_into()?), "foo".parse()?).is_err());