diff --git a/README.md b/README.md index 24051d3..d858cfe 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ Tool for producing identities Anagram of "Gorgon". +## Actions + + * `cargo run -- create eli.key`: makes a new key. + * `cargo run -- sign eli.key message.txt [message.sig]`: signs a message, optionally writes the signature to a file. + ## TODO * Fix up the aegis generation script to ensure that I either have, or don't need, the extensions from Step CA: diff --git a/gongor.rs b/gongor.rs index 49bb796..0e34fdd 100644 --- a/gongor.rs +++ b/gongor.rs @@ -12,6 +12,8 @@ fn main() -> std::io::Result<()>{ if action == "sign" { let keyfilepath = std::env::args().nth(2).expect("no keyfilepath given"); let messagefilepath = std::env::args().nth(3).expect("no message given"); + let maybe_signature_filepath = std::env::args().nth(4); + let mut keyfile = File::open(&keyfilepath).expect("no file found"); let mut keybuffer: [u8; 32] = [0; 32]; @@ -28,7 +30,14 @@ fn main() -> std::io::Result<()>{ println!("Using key {keyfilepath}"); let signature: Signature = signing_key.sign(&messagebuf); - println!("Signture: {signature}"); + if maybe_signature_filepath.is_some() { + let filename = maybe_signature_filepath.expect("Not possible"); + let mut file = File::create(filename.clone())?; + println!("Writing signature to {filename}"); + file.write_all(&signature.to_bytes())?; + } else { + println!("Signture: {signature}"); + } return Ok(()) } else if action == "create" { let keyfilepath = std::env::args().nth(2).expect("no keyfilepath given");