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