refactor: define crypto source trait
This commit is contained in:
parent
f2327778f6
commit
db329e38b4
2 changed files with 27 additions and 3 deletions
|
|
@ -1,4 +1,8 @@
|
||||||
use crate::{certs::CertsAndKeys, log::*};
|
use crate::{
|
||||||
|
certs::{CertsAndKeys, CryptoSource},
|
||||||
|
log::*,
|
||||||
|
};
|
||||||
|
use async_trait::async_trait;
|
||||||
use rustls::{Certificate, PrivateKey};
|
use rustls::{Certificate, PrivateKey};
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
|
|
@ -6,6 +10,26 @@ use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Crypto-related file reader implementing certs::CryptoRead trait
|
||||||
|
pub struct CryptoFileSource {
|
||||||
|
/// tls settings in file
|
||||||
|
pub tls_cert_path: PathBuf,
|
||||||
|
pub tls_cert_key_path: PathBuf,
|
||||||
|
pub client_ca_cert_path: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl CryptoSource for CryptoFileSource {
|
||||||
|
type Error = io::Error;
|
||||||
|
async fn read(&self) -> Result<CertsAndKeys, Self::Error> {
|
||||||
|
read_certs_and_keys(
|
||||||
|
&self.tls_cert_path,
|
||||||
|
&self.tls_cert_key_path,
|
||||||
|
self.client_ca_cert_path.as_ref(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Read certificates and private keys from file
|
/// Read certificates and private keys from file
|
||||||
pub(crate) fn read_certs_and_keys(
|
pub(crate) fn read_certs_and_keys(
|
||||||
cert_path: &PathBuf,
|
cert_path: &PathBuf,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub struct CertsAndKeys {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
// Trait to read certs and keys anywhere from KVS, file, sqlite, etc.
|
// Trait to read certs and keys anywhere from KVS, file, sqlite, etc.
|
||||||
pub trait ReadCerts {
|
pub trait CryptoSource {
|
||||||
type Error;
|
type Error;
|
||||||
async fn read_crypto_source(&self) -> Result<CertsAndKeys, Self::Error>;
|
async fn read(&self) -> Result<CertsAndKeys, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue