idiomatic error handling #1
@ -52,31 +52,15 @@ const KEY_FILE: &str = "/tmp/certs/dtrfs_api.key";
|
||||
const CMDLINE_FILE: &str = "/proc/cmdline";
|
||||
|
||||
lazy_static! {
|
||||
static ref SNP_REPORT: String = match get_cert_hash()
|
||||
.and_then(|hash| snp::get_report_as_base64(hash).map_err(|err| err.into()))
|
||||
{
|
||||
Ok(report) => report,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to get SNP report: {}", e);
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
static ref SNP_REPORT: String = snp::get_report_as_base64(get_cert_hash().unwrap()).unwrap();
|
||||
static ref CRT_CONTENTS: String = {
|
||||
let mut msg = String::new();
|
||||
if let Err(e) =
|
||||
File::open(CRT_FILE).and_then(|file| BufReader::new(file).read_to_string(&mut msg))
|
||||
{
|
||||
eprintln!("Failed to read certificate file: {}", e);
|
||||
}
|
||||
let _ = BufReader::new(File::open(CRT_FILE).unwrap()).read_to_string(&mut msg);
|
||||
msg
|
||||
};
|
||||
static ref CMDLINE: String = {
|
||||
let mut cmdline = String::new();
|
||||
if let Err(e) = File::open(CMDLINE_FILE)
|
||||
.and_then(|file| BufReader::new(file).read_to_string(&mut cmdline))
|
||||
{
|
||||
eprintln!("Failed to read cmdline file: {}", e);
|
||||
}
|
||||
let _ = BufReader::new(File::open(CMDLINE_FILE).unwrap()).read_to_string(&mut cmdline);
|
||||
cmdline
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user