Address comments on pull-request

This commit is contained in:
Jean-Michel Picod
2020-02-20 17:09:08 +01:00
parent 5d9383376b
commit ed6f408063

View File

@@ -52,12 +52,6 @@ fn main() {
let priv_key_vec = pkey.private_key().to_vec(); let priv_key_vec = pkey.private_key().to_vec();
let key_len = priv_key_vec.len(); let key_len = priv_key_vec.len();
assert!(
key_len >= 30,
"Invalid private key (too small): {} ({:#?})",
priv_key_hex,
priv_key_vec,
);
assert!( assert!(
key_len <= 33, key_len <= 33,
"Invalid private key (too big): {} ({:#?})", "Invalid private key (too big): {} ({:#?})",
@@ -68,8 +62,7 @@ fn main() {
// Copy OpenSSL generated key to our vec, starting from the end // Copy OpenSSL generated key to our vec, starting from the end
let mut output_vec = [0u8; 32]; let mut output_vec = [0u8; 32];
let min_key_len = std::cmp::min(key_len, 32); let min_key_len = std::cmp::min(key_len, 32);
output_vec[32usize.saturating_sub(min_key_len)..] output_vec[32 - min_key_len..].copy_from_slice(&priv_key_vec[key_len - min_key_len..]);
.copy_from_slice(&priv_key_vec[key_len.saturating_sub(min_key_len)..]);
// Create the raw private key out of the OpenSSL data // Create the raw private key out of the OpenSSL data
let mut priv_key_bin_file = File::create(&priv_key_bin_path).unwrap(); let mut priv_key_bin_file = File::create(&priv_key_bin_path).unwrap();