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 ssh_key::{rand_core, Algorithm, EcdsaCurve, LineEnding, PrivateKey};
|
||||||
use vergen_gix::{BuildBuilder, CargoBuilder, Emitter, GixBuilder};
|
use vergen_gix::{BuildBuilder, CargoBuilder, Emitter, GixBuilder};
|
||||||
|
|
||||||
const SSH_KEY_ALGOS: &[Algorithm] = &[
|
const SSH_KEY_ALGOS: &[(&'static str, Algorithm)] = &[
|
||||||
Algorithm::Rsa { hash: None },
|
("rsa.pem", Algorithm::Rsa { hash: None }),
|
||||||
Algorithm::Ed25519,
|
("ed25519.pem", Algorithm::Ed25519),
|
||||||
Algorithm::Ecdsa {
|
("ecdsa.pem", Algorithm::Ecdsa {
|
||||||
curve: EcdsaCurve::NistP256,
|
curve: EcdsaCurve::NistP256,
|
||||||
},
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
println!("cargo:rerun-if-changed=Cargo.toml");
|
|
||||||
|
|
||||||
// Generate openSSH host keys
|
// Generate openSSH host keys
|
||||||
let mut rng = rand_core::OsRng::default();
|
let mut rng = rand_core::OsRng::default();
|
||||||
let keys = SSH_KEY_ALGOS
|
let keys = SSH_KEY_ALGOS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|algo| PrivateKey::random(&mut rng, algo.to_owned()).map_err(anyhow::Error::from))
|
.map(|(file_name, algo)| (*file_name, PrivateKey::random(&mut rng, algo.to_owned()).map_err(anyhow::Error::from)))
|
||||||
.collect::<Vec<Result<PrivateKey>>>();
|
.collect::<Vec<(&str, Result<PrivateKey>)>>();
|
||||||
|
|
||||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
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 {
|
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() {
|
if path.exists() {
|
||||||
println!("cargo:warning=Skipping existing host key: {:?}", path.file_stem());
|
println!("cargo:warning=Skipping existing host key: {:?}", path.file_stem());
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue