From 00b5378a62d29f7489075f6d747d50f07cb45caa Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 19:04:32 +0000 Subject: continuum-party keys: files of keys too `keys --add`, `--remove` and `--set` took authorized_keys lines alone, each one argument, so a .pub file went in as "$(cat phone.pub)". They take files of such lines too now, as `propose admit` and `propose keys` do (keys_given, of which key_lines is the one asking for a key at least), and bash completes files there. --- src/federation/party.rs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/federation') diff --git a/src/federation/party.rs b/src/federation/party.rs index 55ad5a5..492a76b 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -10,10 +10,11 @@ //! FILE`, from the file the store's swarm starts from, for a party that never voted in //! it: the record casts on every version, the first too; //! * `write PATH VALUE`: writes `VALUE` (JSON) at `PATH`; -//! * `keys`, `nodes`: the party's key set (`authorized_keys` lines, each one argument, -//! their comments left out) or node list (node IDs) as it counts at the node, one a line -//! (`--list`); or written: with `--add` and `--remove`, the set or list as it counts, -//! changed; with `--set`, set whole. One left empty is written with `--force` only; +//! * `keys`, `nodes`: the party's key set (`authorized_keys` lines, each one argument, or +//! files of them, their comments left out) or node list (node IDs) as it counts at the +//! node, one a line (`--list`); or written: with `--add` and `--remove`, the set or list +//! as it counts, changed; with `--set`, set whole. One left empty is written with +//! `--force` only; //! * `next`: the version after the current one, to change and propose: the current one //! numbered on, naming its hash, without its checkpoint (JSON), to standard output; //! * `propose FILE`: proposes the version `FILE` holds (JSON), where a party may back it @@ -131,7 +132,7 @@ fn command() -> Command { "The party's key set as it counts at the node, or written with keys added, \ taken off, or set whole", ) - .args(changing("KEY", "keys", "key set")) + .args(changing("KEY|FILE", "keys", "key set")) .group(changes()), ) .subcommand( @@ -843,16 +844,7 @@ pub(crate) async fn main() -> Result<()> { } ("keys", sub) => { // As the federation spells a key: without the line's comment. - let spelled = |name: &str| { - strings(sub, name) - .iter() - .map(|line| { - Key::parse(line) - .map(|key| key.line()) - .map_err(|why| anyhow!("{line:?}: {why}")) - }) - .collect::>>() - }; + let spelled = |name: &str| keys_given(&strings(sub, name)); let counts = node.counts().await?; signer.named_by(¤t(&counts)?)?; let party = &signer.party; @@ -1059,8 +1051,17 @@ async fn proposal_version(node: &Node, counts: &JsonValue, proposal: Id) -> Resu /// The keys `given` names, as the federation spells them (without comments): each an /// `authorized_keys` line itself, or a file of such lines, blank ones and `#` comments -/// left out; none twice. +/// left out; none twice, one at least. fn key_lines(given: &[String]) -> Result> { + let lines = keys_given(given)?; + if lines.is_empty() { + bail!("no key given: a party signs with the keys a version names"); + } + Ok(lines) +} + +/// As `key_lines`, none too. +fn keys_given(given: &[String]) -> Result> { let mut lines: Vec = Vec::new(); for item in given { let found = match Key::parse(item) { @@ -1084,9 +1085,6 @@ fn key_lines(given: &[String]) -> Result> { lines.push(line); } } - if lines.is_empty() { - bail!("no key given: a party signs with the keys a version names"); - } Ok(lines) } -- cgit v1.3.1