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