fix clippy warnings

This commit is contained in:
Noor 2025-03-21 20:42:46 +05:30
parent 683c49564d
commit 88d3207cb5
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
2 changed files with 13 additions and 16 deletions

@ -390,14 +390,14 @@ impl Config {
let private_key_path = Self::hratls_key_path()?; let private_key_path = Self::hratls_key_path()?;
if Path::new(&private_key_path).exists() { if Path::new(&private_key_path).exists() {
log::debug!("Found HRaTLS private key at {private_key_path}"); log::debug!("Found HRaTLS private key at {private_key_path}");
return Ok(std::fs::read_to_string(private_key_path) return std::fs::read_to_string(private_key_path)
.map_err(|e| Error::CorruptedHratlsKey(e.to_string()))?); .map_err(|e| Error::CorruptedHratlsKey(e.to_string()));
} }
let key = PKey::generate_ed25519()?; let key = PKey::generate_ed25519()?;
let mut key_file = File::create(private_key_path)?; let mut key_file = File::create(private_key_path)?;
let pem_pkcs8 = key.private_key_to_pem_pkcs8()?; let pem_pkcs8 = key.private_key_to_pem_pkcs8()?;
key_file.write_all(&pem_pkcs8)?; key_file.write_all(&pem_pkcs8)?;
Ok(String::from_utf8(pem_pkcs8).map_err(|e| Error::CorruptedHratlsKey(e.to_string()))?) String::from_utf8(pem_pkcs8).map_err(|e| Error::CorruptedHratlsKey(e.to_string()))
} }
pub fn get_hratls_pubkey_hex() -> Result<String, Error> { pub fn get_hratls_pubkey_hex() -> Result<String, Error> {
@ -430,22 +430,22 @@ impl Config {
fn get_mrsigner_rsa_key() -> Result<Rsa<Private>, Error> { fn get_mrsigner_rsa_key() -> Result<Rsa<Private>, Error> {
let signing_key_pem_str = Self::create_mrsigner_rsa_key()?; let signing_key_pem_str = Self::create_mrsigner_rsa_key()?;
Ok(Rsa::private_key_from_pem(signing_key_pem_str.as_ref()) Rsa::private_key_from_pem(signing_key_pem_str.as_ref())
.map_err(|e| Error::CorruptedMrSigner(e.to_string()))?) .map_err(|e| Error::CorruptedMrSigner(e.to_string()))
} }
fn create_mrsigner_rsa_key() -> Result<String, Error> { fn create_mrsigner_rsa_key() -> Result<String, Error> {
let signing_key_path = Self::mrsigner_key_path()?; let signing_key_path = Self::mrsigner_key_path()?;
if Path::new(&signing_key_path).exists() { if Path::new(&signing_key_path).exists() {
log::debug!("Found signing_key at {signing_key_path}"); log::debug!("Found signing_key at {signing_key_path}");
return Ok(std::fs::read_to_string(signing_key_path) return std::fs::read_to_string(signing_key_path)
.map_err(|e| Error::CorruptedMrSigner(e.to_string()))?); .map_err(|e| Error::CorruptedMrSigner(e.to_string()));
} }
let key = Rsa::generate_with_e(3072, BigNum::from_u32(3)?.as_ref())?; let key = Rsa::generate_with_e(3072, BigNum::from_u32(3)?.as_ref())?;
let mut key_file = File::create(signing_key_path)?; let mut key_file = File::create(signing_key_path)?;
let pem_pkcs8 = key.private_key_to_pem()?; let pem_pkcs8 = key.private_key_to_pem()?;
key_file.write_all(&pem_pkcs8)?; key_file.write_all(&pem_pkcs8)?;
Ok(String::from_utf8(pem_pkcs8).map_err(|e| Error::CorruptedMrSigner(e.to_string()))?) String::from_utf8(pem_pkcs8).map_err(|e| Error::CorruptedMrSigner(e.to_string()))
} }
pub fn mrsigner_key_path() -> Result<String, Error> { pub fn mrsigner_key_path() -> Result<String, Error> {

@ -63,14 +63,11 @@ impl Args {
})?; })?;
if !script_result.status.success() { if !script_result.status.success() {
return Err(Error::FailedExecution(format!( return Err(Error::FailedExecution(format!(
"sev-snp-measure.py failed: {}", "sev-snp-measure.py failed: !!! stdout:\n{}\n!!! stderr:\n{}",
format!( String::from_utf8(script_result.stdout.clone())
"!!! stdout:\n{}\n!!! stderr:\n{}", .unwrap_or("Could not grab stdout from installation script.".to_string()),
String::from_utf8(script_result.stdout.clone()) String::from_utf8(script_result.stderr.clone())
.unwrap_or("Could not grab stdout from installation script.".to_string()), .unwrap_or("Could not grab stderr from installation script.".to_string())
String::from_utf8(script_result.stderr.clone())
.unwrap_or("Could not grab stderr from installation script.".to_string())
)
))); )));
} }
Ok(String::from_utf8(script_result.stdout) Ok(String::from_utf8(script_result.stdout)