refactor(lib):删除暂时无用的errors模块。
This commit is contained in:
parent
69a749b6a2
commit
1f7ff5e66a
|
@ -1,9 +0,0 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CertificateGenerateError {
|
||||
#[error("Error generating RSA key")]
|
||||
X509Error(#[from] openssl::error::ErrorStack),
|
||||
#[error("IO Error")]
|
||||
IOError(#[from] std::io::Error),
|
||||
}
|
|
@ -13,7 +13,6 @@ use openssl::{
|
|||
x509::X509Builder,
|
||||
};
|
||||
|
||||
pub mod errors;
|
||||
mod root_certificate;
|
||||
|
||||
/// 生成证书,公钥保存为.pem文件,私钥保存为.key文件
|
||||
|
@ -101,3 +100,25 @@ pub fn calculate_power_euqal_result(cert: X509) -> anyhow::Result<String> {
|
|||
result.to_dec_str()?
|
||||
))
|
||||
}
|
||||
|
||||
/// 从.pem文件中读取X509证书
|
||||
///
|
||||
/// - `file_path`:证书文件路径
|
||||
pub fn load_certificate<P: AsRef<Path>>(file_path: P) -> anyhow::Result<X509> {
|
||||
let file_path = file_path.as_ref();
|
||||
let cert_pem = fs::read(file_path)?;
|
||||
let cert = X509::from_pem(&cert_pem)?;
|
||||
Ok(cert)
|
||||
}
|
||||
|
||||
/// 从.key文件中读取RSA私钥
|
||||
///
|
||||
/// - `file_path`:私钥文件路径
|
||||
pub fn load_private_key<R: AsRef<Path>>(
|
||||
file_path: R,
|
||||
) -> anyhow::Result<PKey<openssl::pkey::Private>> {
|
||||
let file_path = file_path.as_ref();
|
||||
let key_pem = fs::read(file_path)?;
|
||||
let key = PKey::private_key_from_pem(&key_pem)?;
|
||||
Ok(key)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user