mirror of
https://github.com/str4d/rage.git
synced 2025-04-03 19:07:42 +03:00
age: Add labels extension to client side of recipient-v1
This commit is contained in:
parent
8f1d6af149
commit
2d29668712
2 changed files with 34 additions and 2 deletions
|
@ -21,6 +21,7 @@ to 1.0.0 are beta releases.
|
|||
- `age::Recipient::wrap_file_key` now returns `(Vec<Stanza>, HashSet<String>)`:
|
||||
a tuple of the stanzas to be placed in an age file header, and labels that
|
||||
constrain how the stanzas may be combined with those from other recipients.
|
||||
- `age::plugin::RecipientPluginV1` now supports the labels extension.
|
||||
|
||||
### Removed
|
||||
- `age::decryptor::PassphraseDecryptor` (use `age::Decryptor` with
|
||||
|
|
|
@ -33,6 +33,7 @@ const PLUGIN_IDENTITY_PREFIX: &str = "age-plugin-";
|
|||
|
||||
const CMD_ERROR: &str = "error";
|
||||
const CMD_RECIPIENT_STANZA: &str = "recipient-stanza";
|
||||
const CMD_LABELS: &str = "labels";
|
||||
const CMD_MSG: &str = "msg";
|
||||
const CMD_CONFIRM: &str = "confirm";
|
||||
const CMD_REQUEST_PUBLIC: &str = "request-public";
|
||||
|
@ -395,12 +396,13 @@ impl<C: Callbacks> crate::Recipient for RecipientPluginV1<C> {
|
|||
for identity in &self.identities {
|
||||
phase.send("add-identity", &[&identity.identity], &[])?;
|
||||
}
|
||||
phase.send("extension-labels", &[], &[])?;
|
||||
phase.send("wrap-file-key", &[], file_key.expose_secret())
|
||||
})?;
|
||||
|
||||
// Phase 2: collect either stanzas or errors
|
||||
let mut stanzas = vec![];
|
||||
let labels = HashSet::new();
|
||||
let mut labels = None;
|
||||
let mut errors = vec![];
|
||||
if let Err(e) = conn.bidir_receive(
|
||||
&[
|
||||
|
@ -409,6 +411,7 @@ impl<C: Callbacks> crate::Recipient for RecipientPluginV1<C> {
|
|||
CMD_REQUEST_PUBLIC,
|
||||
CMD_REQUEST_SECRET,
|
||||
CMD_RECIPIENT_STANZA,
|
||||
CMD_LABELS,
|
||||
CMD_ERROR,
|
||||
],
|
||||
|mut command, reply| match command.tag.as_str() {
|
||||
|
@ -464,6 +467,34 @@ impl<C: Callbacks> crate::Recipient for RecipientPluginV1<C> {
|
|||
}
|
||||
reply.ok(None)
|
||||
}
|
||||
CMD_LABELS => {
|
||||
if labels.is_none() {
|
||||
let labels_count = command.args.len();
|
||||
let label_set = command.args.into_iter().collect::<HashSet<_>>();
|
||||
if label_set.len() == labels_count {
|
||||
labels = Some(label_set);
|
||||
} else {
|
||||
errors.push(PluginError::Other {
|
||||
kind: "internal".to_owned(),
|
||||
metadata: vec![],
|
||||
message: format!(
|
||||
"{} command must not contain duplicate labels",
|
||||
CMD_LABELS
|
||||
),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
errors.push(PluginError::Other {
|
||||
kind: "internal".to_owned(),
|
||||
metadata: vec![],
|
||||
message: format!(
|
||||
"{} command must not be sent more than once",
|
||||
CMD_LABELS
|
||||
),
|
||||
});
|
||||
}
|
||||
reply.ok(None)
|
||||
}
|
||||
CMD_ERROR => {
|
||||
if command.args.len() == 2 && command.args[0] == "recipient" {
|
||||
let index: usize = command.args[1].parse().unwrap();
|
||||
|
@ -489,7 +520,7 @@ impl<C: Callbacks> crate::Recipient for RecipientPluginV1<C> {
|
|||
return Err(e.into());
|
||||
};
|
||||
match (stanzas.is_empty(), errors.is_empty()) {
|
||||
(false, true) => Ok((stanzas, labels)),
|
||||
(false, true) => Ok((stanzas, labels.unwrap_or_default())),
|
||||
(a, b) => {
|
||||
if a & b {
|
||||
errors.push(PluginError::Other {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue