Skip to content

Commit

Permalink
Assert that supported SSH identities can't produce ignored recipients
Browse files Browse the repository at this point in the history
We produce an error before this point for unsupported SSH identities,
and ignored recipients are a subset of these. A panic here would
indicate a programming error in the `age` crate.
  • Loading branch information
str4d committed Jan 17, 2024
1 parent fe2f9d6 commit d39ebfe
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rage/src/bin/rage/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ macro_rules! warning {
}};
}

/// Handles error mapping for the given SSH recipient parser.
///
/// Returns `Ok(None)` if the parser finds a parseable value that should be ignored. This
/// case is for handling SSH recipient types that may occur in files we want to be able to
/// parse, but that we do not directly support.
#[cfg(feature = "ssh")]
fn parse_ssh_recipient<F, G>(
parser: F,
Expand Down Expand Up @@ -174,14 +179,14 @@ fn read_recipients(
return Err(error::EncryptError::UnsupportedKey(filename, k))
}
Ok(identity) => {
if let Some(recipient) = parse_ssh_recipient(
let recipient = parse_ssh_recipient(
|| age::ssh::Recipient::try_from(identity),
|| Err(error::EncryptError::InvalidRecipient(filename.clone())),
&filename,
)? {
recipients.push(recipient);
continue;
}
)?
.expect("unsupported identities were already handled");
recipients.push(recipient);
continue;
}
Err(_) => (),
}
Expand Down

0 comments on commit d39ebfe

Please sign in to comment.