From 297dca28f3dd1f3ded97c7539823900294efb4da Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 7 Nov 2020 21:41:04 +0800 Subject: [PATCH] feat: add args --- __enclave/virt_enclave/examples/sign_file.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/__enclave/virt_enclave/examples/sign_file.rs b/__enclave/virt_enclave/examples/sign_file.rs index 0dc4fa2..ff0a06d 100644 --- a/__enclave/virt_enclave/examples/sign_file.rs +++ b/__enclave/virt_enclave/examples/sign_file.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{ Read, Write }; use std::fs::File; use ring::digest; use virt_enclave::sig::*; @@ -31,4 +31,15 @@ fn main() { println!("File : {}", f); println!("Hex : {}", digest_hex); println!("Signed: {}", serde_json::to_string(&signed_message).unwrap()); + + if let Some(of) = args.next() { + if File::open(&of).is_ok() { + println!("Output file exists: {}", of); + return; + } + if let Ok(mut out_file) = File::create(&of) { + out_file.write_all(&serde_json::to_string(&signed_message).unwrap().as_bytes()).ok(); + println!("Write file successed: {}", of); + } + } } \ No newline at end of file