Skip to content

Commit

Permalink
feat: 编译时内联key
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed May 5, 2024
1 parent 3f3bb4e commit 4a55bf2
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/ca/mod.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
use anyhow::{anyhow, Result};
use std::{fs::read_to_string, path::Path};
use anyhow::Result;

// 返回:(公钥,私钥)
pub fn get_own_pair() -> Result<(String, String)> {
check()?;
let public_file = read_to_string("./keys/public.pem")?;
let private_file = read_to_string("./keys/private.key")?;
let public_file = include_str!("../../keys/public.pem").to_string();
let private_file = include_str!("../../keys/private.key").to_string();
Ok((public_file, private_file))
}

pub fn query_others_public(_email: &String) -> Result<String> {
check()?;
let public_file = read_to_string("./keys/public.pem")?;
let public_file = include_str!("../../keys/public.pem").to_string();
Ok(public_file)
}

fn check() -> Result<()> {
let manifest = vec!["./keys/public.pem", "./keys/private.key"];
for file_name in manifest {
let p = Path::new(&file_name);
if !p.exists() {
return Err(anyhow!(
"Error:Missing '{file_name}', please place 'keys' folder in current dir"
));
}
}

Ok(())
}

0 comments on commit 4a55bf2

Please sign in to comment.