1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![allow(dead_code)]

use std::{path::Path, process::Command};

pub mod committee;
mod crs;
mod election_public_key;
mod tally;

pub use committee::CommitteeCommand;
pub use crs::CrsCommand;
pub use election_public_key::ElectionPublicKeyCommand;
pub use tally::TallyCommand;

#[derive(Debug)]
pub struct VotesCommand {
    command: Command,
}

impl VotesCommand {
    pub fn new(command: Command) -> Self {
        Self { command }
    }

    pub fn crs(mut self) -> CrsCommand {
        self.command.arg("crs");
        CrsCommand::new(self.command)
    }

    pub fn committee(mut self) -> CommitteeCommand {
        self.command.arg("committee");
        CommitteeCommand::new(self.command)
    }

    pub fn election_public_key<S: Into<String>, P: AsRef<Path>>(
        mut self,
        member_key: S,
        output_file: P,
    ) -> Self {
        self.command
            .arg("election-key")
            .arg(output_file.as_ref())
            .arg("--keys")
            .arg(member_key.into());
        self
    }

    pub fn tally(mut self) -> TallyCommand {
        self.command.arg("tally");
        TallyCommand::new(self.command)
    }

    pub fn update_proposal<P: AsRef<Path>, Q: AsRef<Path>>(mut self, config: P, secret: Q) -> Self {
        self.command
            .arg("update-proposal")
            .arg(config.as_ref())
            .arg("--secret")
            .arg(secret.as_ref());
        self
    }

    pub fn update_vote<R: Into<String>, P: AsRef<Path>>(
        mut self,
        proposal_id: R,
        secret: P,
    ) -> Self {
        self.command
            .arg("update-vote")
            .arg(proposal_id.into())
            .arg("--secret")
            .arg(secret.as_ref());
        self
    }

    pub fn build(self) -> Command {
        self.command
    }
}