23 lines
810 B
Rust
23 lines
810 B
Rust
use std::fs::File;
|
|
use std::io::Read;
|
|
use crate::sig::SigningKeyPair;
|
|
use rust_util::XResult;
|
|
|
|
lazy_static::lazy_static! {
|
|
static ref SIGNING_KEY_PAIR: Option<SigningKeyPair> = load_signing_key_pair();
|
|
}
|
|
|
|
pub fn get_signing_public_key() -> Option<String> {
|
|
SIGNING_KEY_PAIR.as_ref().map(|key_pair| hex::encode(&key_pair.public_key()))
|
|
}
|
|
|
|
pub fn load_signing_key_pair() -> Option<SigningKeyPair> {
|
|
SigningKeyPair::read_from_file("platform_signing_key.json").ok()
|
|
}
|
|
|
|
pub fn read_file(f: &str) -> XResult<String> {
|
|
let mut file = File::open(&f).map_err(|e| rust_util::new_box_error(&format!("Open file: {}, failed: {}", f , e)))?;
|
|
let mut buf = String::new();
|
|
file.read_to_string(&mut buf).map_err(|e| rust_util::new_box_error(&format!("Read file: {}, failed: {}", f , e)))?;
|
|
Ok(buf)
|
|
} |