aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation')
-rw-r--r--src/federation/party.rs36
1 files changed, 17 insertions, 19 deletions
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::<Result<Vec<String>>>()
- };
+ let spelled = |name: &str| keys_given(&strings(sub, name));
let counts = node.counts().await?;
signer.named_by(&current(&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<Vec<String>> {
+ 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<Vec<String>> {
let mut lines: Vec<String> = Vec::new();
for item in given {
let found = match Key::parse(item) {
@@ -1084,9 +1085,6 @@ fn key_lines(given: &[String]) -> Result<Vec<String>> {
lines.push(line);
}
}
- if lines.is_empty() {
- bail!("no key given: a party signs with the keys a version names");
- }
Ok(lines)
}