age: Pass entire IdentityFile to parse_identity_files closure

This commit is contained in:
Jack Grigg 2024-08-23 22:49:47 +00:00
parent 5086bd65d9
commit d31fb568b7
2 changed files with 28 additions and 28 deletions

View file

@ -33,26 +33,28 @@ pub fn read_identities(
identities.push(Box::new(identity.with_callbacks(UiCallbacks)));
Ok(())
},
|identities, entry| {
let entry = entry.into_identity(UiCallbacks);
|identities, identity_file| {
for entry in identity_file.into_identities() {
let entry = entry.into_identity(UiCallbacks);
#[cfg(feature = "plugin")]
let entry = entry.map_err(|e| match e {
#[cfg(feature = "plugin")]
crate::DecryptError::MissingPlugin { binary_name } => {
ReadError::MissingPlugin { binary_name }
}
// DecryptError::MissingPlugin is the only possible error kind returned by
// IdentityFileEntry::into_identity.
_ => unreachable!(),
})?;
let entry = entry.map_err(|e| match e {
#[cfg(feature = "plugin")]
crate::DecryptError::MissingPlugin { binary_name } => {
ReadError::MissingPlugin { binary_name }
}
// DecryptError::MissingPlugin is the only possible error kind returned by
// IdentityFileEntry::into_identity.
_ => unreachable!(),
})?;
// IdentityFileEntry::into_identity will never return a MissingPlugin error
// when plugin feature is not enabled.
#[cfg(not(feature = "plugin"))]
let entry = entry.unwrap();
// IdentityFileEntry::into_identity will never return a MissingPlugin error
// when plugin feature is not enabled.
#[cfg(not(feature = "plugin"))]
let entry = entry.unwrap();
identities.push(entry);
identities.push(entry);
}
Ok(())
},
@ -72,7 +74,7 @@ pub(super) fn parse_identity_files<Ctx, E: From<ReadError> + From<io::Error>>(
crate::encrypted::Identity<ArmoredReader<BufReader<InputReader>>, UiCallbacks>,
) -> Result<(), E>,
#[cfg(feature = "ssh")] ssh_identity: impl Fn(&mut Ctx, &str, crate::ssh::Identity) -> Result<(), E>,
identity_file_entry: impl Fn(&mut Ctx, crate::IdentityFileEntry) -> Result<(), E>,
identity_file: impl Fn(&mut Ctx, crate::IdentityFile) -> Result<(), E>,
) -> Result<(), E> {
for filename in filenames {
#[cfg_attr(not(any(feature = "armor", feature = "ssh")), allow(unused_mut))]
@ -135,11 +137,7 @@ pub(super) fn parse_identity_files<Ctx, E: From<ReadError> + From<io::Error>>(
reader.reset()?;
// Try parsing as multiple single-line age identities.
let identity_file = IdentityFile::from_buffer(reader)?;
for entry in identity_file.into_identities() {
identity_file_entry(ctx, entry)?;
}
identity_file(ctx, IdentityFile::from_buffer(reader)?)?;
}
Ok(())

View file

@ -210,13 +210,15 @@ pub fn read_recipients(
recipients.push(recipient);
Ok(())
},
|recipients, entry| {
#[cfg(feature = "plugin")]
let (recipients, plugin_identities) = recipients;
match entry {
IdentityFileEntry::Native(i) => recipients.push(Box::new(i.to_public())),
|recipients, identity_file| {
for entry in identity_file.into_identities() {
#[cfg(feature = "plugin")]
IdentityFileEntry::Plugin(i) => plugin_identities.push(i),
let (recipients, plugin_identities) = recipients;
match entry {
IdentityFileEntry::Native(i) => recipients.push(Box::new(i.to_public())),
#[cfg(feature = "plugin")]
IdentityFileEntry::Plugin(i) => plugin_identities.push(i),
}
}
Ok(())
},