use crate::constants::ACME_ACCOUNT_SUBDIR;
use async_trait::async_trait;
use aws_lc_rs as crypto;
use base64::prelude::*;
use blocking::unblock;
use crypto::digest::{Context, SHA256};
use rustls_acme::{AccountCache, CertCache};
use std::{
io::ErrorKind,
path::{Path, PathBuf},
};
enum FileType {
Account,
Cert,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct DirCache {
pub(super) account_dir: PathBuf,
pub(super) cert_dir: PathBuf,
}
impl DirCache {
pub fn new
(dir: P, server_name: &str) -> Self
where
P: AsRef,
{
Self {
account_dir: dir.as_ref().join(ACME_ACCOUNT_SUBDIR),
cert_dir: dir.as_ref().join(server_name),
}
}
async fn read_if_exist(&self, file: impl AsRef, file_type: FileType) -> Result