forked from DevComp/ssh-portfolio
chore(build): no need to rebuild for Cargo.toml changes
This commit is contained in:
parent
bcc667f3ea
commit
7bbae7f21c
1 changed files with 9 additions and 10 deletions
19
build.rs
19
build.rs
|
@ -4,29 +4,28 @@ use anyhow::Result;
|
|||
use ssh_key::{rand_core, Algorithm, EcdsaCurve, LineEnding, PrivateKey};
|
||||
use vergen_gix::{BuildBuilder, CargoBuilder, Emitter, GixBuilder};
|
||||
|
||||
const SSH_KEY_ALGOS: &[Algorithm] = &[
|
||||
Algorithm::Rsa { hash: None },
|
||||
Algorithm::Ed25519,
|
||||
Algorithm::Ecdsa {
|
||||
const SSH_KEY_ALGOS: &[(&'static str, Algorithm)] = &[
|
||||
("rsa.pem", Algorithm::Rsa { hash: None }),
|
||||
("ed25519.pem", Algorithm::Ed25519),
|
||||
("ecdsa.pem", Algorithm::Ecdsa {
|
||||
curve: EcdsaCurve::NistP256,
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
fn main() -> Result<()> {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=Cargo.toml");
|
||||
|
||||
// Generate openSSH host keys
|
||||
let mut rng = rand_core::OsRng::default();
|
||||
let keys = SSH_KEY_ALGOS
|
||||
.iter()
|
||||
.map(|algo| PrivateKey::random(&mut rng, algo.to_owned()).map_err(anyhow::Error::from))
|
||||
.collect::<Vec<Result<PrivateKey>>>();
|
||||
.map(|(file_name, algo)| (*file_name, PrivateKey::random(&mut rng, algo.to_owned()).map_err(anyhow::Error::from)))
|
||||
.collect::<Vec<(&str, Result<PrivateKey>)>>();
|
||||
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
for key_res in keys {
|
||||
for (file_name, key_res) in keys {
|
||||
if let Ok(ref key) = key_res {
|
||||
let path = out_dir.join(format!("{}.pem", key.algorithm().as_str()));
|
||||
let path = out_dir.join(file_name);
|
||||
if path.exists() {
|
||||
println!("cargo:warning=Skipping existing host key: {:?}", path.file_stem());
|
||||
continue;
|
||||
|
|
Loading…
Add table
Reference in a new issue