|
1 | 1 | //! Recipient plugin helpers. |
2 | 2 |
|
3 | 3 | use age_core::{ |
4 | | - format::{is_arbitrary_string, FileKey, Stanza, FILE_KEY_BYTES}, |
| 4 | + format::{is_arbitrary_string, FileKey, Stanza}, |
5 | 5 | plugin::{self, BidirSend, Connection}, |
6 | 6 | secrecy::SecretString, |
7 | 7 | }; |
@@ -81,8 +81,12 @@ pub trait RecipientPluginV1 { |
81 | 81 | /// Wraps each `file_key` to all recipients and identities previously added via |
82 | 82 | /// `add_recipient` and `add_identity`. |
83 | 83 | /// |
84 | | - /// Returns either one stanza per recipient and identity for each file key, or any |
85 | | - /// errors if one or more recipients or identities could not be wrapped to. |
| 84 | + /// Returns a set of stanzas per file key that wrap it to each recipient and identity. |
| 85 | + /// Plugins may return more than one stanza per "actual recipient", e.g. to support |
| 86 | + /// multiple formats, to build group aliases, or to act as a proxy. |
| 87 | + /// |
| 88 | + /// If one or more recipients or identities could not be wrapped to, no stanzas are |
| 89 | + /// returned for any of the file keys. |
86 | 90 | /// |
87 | 91 | /// `callbacks` can be used to interact with the user, to have them take some physical |
88 | 92 | /// action or request a secret value. |
@@ -183,7 +187,7 @@ impl<'a, 'b, R: io::Read, W: io::Write> Callbacks<Error> for BidirCallbacks<'a, |
183 | 187 | .and_then(|res| match res { |
184 | 188 | Ok(s) => String::from_utf8(s.body) |
185 | 189 | .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "secret is not UTF-8")) |
186 | | - .map(|s| Ok(SecretString::new(s))), |
| 190 | + .map(|s| Ok(SecretString::from(s))), |
187 | 191 | Err(e) => Ok(Err(e)), |
188 | 192 | }) |
189 | 193 | } |
@@ -281,11 +285,16 @@ pub(crate) fn run_v1<P: RecipientPluginV1>(mut plugin: P) -> io::Result<()> { |
281 | 285 | }), |
282 | 286 | (Some(WRAP_FILE_KEY), |s| { |
283 | 287 | // TODO: Should we ignore file key commands with unexpected metadata args? |
284 | | - TryInto::<[u8; FILE_KEY_BYTES]>::try_into(&s.body[..]) |
285 | | - .map_err(|_| Error::Internal { |
286 | | - message: "invalid file key length".to_owned(), |
287 | | - }) |
288 | | - .map(FileKey::from) |
| 288 | + FileKey::try_init_with_mut(|file_key| { |
| 289 | + if s.body.len() == file_key.len() { |
| 290 | + file_key.copy_from_slice(&s.body); |
| 291 | + Ok(()) |
| 292 | + } else { |
| 293 | + Err(Error::Internal { |
| 294 | + message: "invalid file key length".to_owned(), |
| 295 | + }) |
| 296 | + } |
| 297 | + }) |
289 | 298 | }), |
290 | 299 | (Some(EXTENSION_LABELS), |_| Ok(())), |
291 | 300 | )?; |
|
0 commit comments