Skip to content

Commit

Permalink
Merge 97785b8 into 48abe33
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed May 28, 2019
2 parents 48abe33 + 97785b8 commit 963470a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ readme = "README.md"
chrono = {version = "0.4.2", features = ['serde']}
failure = "0.1.1"
log = "0.4.2"
ring = "0.12.1"
ring = "*"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
untrusted = "0.5.1"
untrusted = "*"

[[bin]]
name = "gen_license"
Expand Down
19 changes: 13 additions & 6 deletions bin/gen_keys.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate ring;
extern crate untrusted;

use ring::signature::KeyPair;
use std::env;
use std::fs;
use std::process::exit;
Expand All @@ -20,16 +21,22 @@ fn main() -> Result<(), String> {
};
// Generate a key pair in PKCS#8 (v2) format.
let rng = rand::SystemRandom::new();
let pkcs8_bytes = signature::Ed25519KeyPair::generate_pkcs8(&rng).map_err(|e| format!("Error: {:?}", e))?;
let pkcs8_bytes =
signature::Ed25519KeyPair::generate_pkcs8(&rng).map_err(|e| format!("Error: {:?}", e))?;

// Normally the application would store the PKCS#8 file persistently. Later
// it would read the PKCS#8 file from persistent storage to use it.

let key_pair =
signature::Ed25519KeyPair::from_pkcs8(
untrusted::Input::from(&pkcs8_bytes)).map_err(|e| format!("Error: {:?}", e))?;
fs::write(&format!("{}/private.pks", key_path), pkcs8_bytes.as_ref()).map_err(|e| format!("FS Error: {:?}", e))?;
signature::Ed25519KeyPair::from_pkcs8(untrusted::Input::from(pkcs8_bytes.as_ref()))
.map_err(|e| format!("Error: {:?}", e))?;
fs::write(&format!("{}/private.pks", key_path), pkcs8_bytes.as_ref())
.map_err(|e| format!("FS Error: {:?}", e))?;

fs::write(&format!("{}/public.pks", key_path), &key_pair.public_key_bytes()).map_err(|e| format!("FS Error: {:?}", e))?;
fs::write(
&format!("{}/public.pks", key_path),
&key_pair.public_key().as_ref(),
)
.map_err(|e| format!("FS Error: {:?}", e))?;
Ok(())
}
}

0 comments on commit 963470a

Please sign in to comment.