DNS, DKIM and ACME improvements - part 1
This commit is contained in:
@@ -38,36 +38,59 @@ impl<T: MapItem> Map<T> {
|
||||
Self(Vec::with_capacity(capacity))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn contains(&self, item: &T) -> bool {
|
||||
self.0.contains(item)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> Vec<T> {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn inner_mut(&mut self) -> &mut Vec<T> {
|
||||
&mut self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn iter(&self) -> impl Iterator<Item = &T> {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
self.0.iter_mut()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn as_slice(&self) -> &[T] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn push(&mut self, item: T) {
|
||||
if !self.0.contains(&item) {
|
||||
self.0.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn push_unchecked(&mut self, item: T) {
|
||||
self.0.push(item);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn clear(&mut self) {
|
||||
self.0.clear();
|
||||
}
|
||||
|
||||
28
crates/registry/src/utils/dkim.rs
Normal file
28
crates/registry/src/utils/dkim.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::schema::enums::DkimSignatureType;
|
||||
|
||||
impl DkimSignatureType {
|
||||
pub const fn algorithm(self) -> &'static str {
|
||||
match self {
|
||||
Self::Dkim1Ed25519Sha256 => "ed25519",
|
||||
Self::Dkim1RsaSha256 => "rsa",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn hash(self) -> &'static str {
|
||||
match self {
|
||||
Self::Dkim1Ed25519Sha256 | Self::Dkim1RsaSha256 => "sha256",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn version(self) -> &'static str {
|
||||
match self {
|
||||
Self::Dkim1Ed25519Sha256 | Self::Dkim1RsaSha256 => "1",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,13 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::schema::prelude::{DkimPrivateKey, DkimSignature, Roles};
|
||||
use crate::schema::prelude::{DkimSignature, Roles, SecretKey};
|
||||
use types::id::Id;
|
||||
|
||||
pub mod account;
|
||||
pub mod archived_item;
|
||||
pub mod cron;
|
||||
pub mod dkim;
|
||||
pub mod http;
|
||||
pub mod report;
|
||||
pub mod secret;
|
||||
@@ -27,28 +26,17 @@ impl Roles {
|
||||
}
|
||||
|
||||
impl DkimSignature {
|
||||
pub fn private_key(&self) -> &DkimPrivateKey {
|
||||
pub fn private_key(&self) -> &SecretKey {
|
||||
match self {
|
||||
DkimSignature::Dkim1Ed25519Sha256(signature) => &signature.private_key,
|
||||
DkimSignature::Dkim1RsaSha256(signature) => &signature.private_key,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn private_key_mut(&mut self) -> &mut DkimPrivateKey {
|
||||
pub fn private_key_mut(&mut self) -> &mut SecretKey {
|
||||
match self {
|
||||
DkimSignature::Dkim1Ed25519Sha256(signature) => &mut signature.private_key,
|
||||
DkimSignature::Dkim1RsaSha256(signature) => &mut signature.private_key,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DkimPrivateKey {
|
||||
pub async fn pem(&self) -> trc::Result<Cow<'_, str>> {
|
||||
match self {
|
||||
DkimPrivateKey::Value(value) => Ok(Cow::Borrowed(value.secret.as_str())),
|
||||
DkimPrivateKey::File(file) => file.secret().await.map(Cow::Owned),
|
||||
DkimPrivateKey::Generate => Err("Key is in invalid generate state".to_string()),
|
||||
}
|
||||
.map_err(|err| trc::DkimEvent::BuildError.reason(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ impl Task {
|
||||
Task::AccountMaintenance(task) => task.status = status,
|
||||
Task::StoreMaintenance(task) => task.status = status,
|
||||
Task::SpamFilterMaintenance(task) => task.status = status,
|
||||
Task::AcmeRenewal(task) => task.status = status,
|
||||
Task::DkimKeyRotation(task) => task.status = status,
|
||||
Task::DnsManagement(task) => task.status = status,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +48,9 @@ impl Task {
|
||||
Task::AccountMaintenance(task) => &task.status,
|
||||
Task::StoreMaintenance(task) => &task.status,
|
||||
Task::SpamFilterMaintenance(task) => &task.status,
|
||||
Task::AcmeRenewal(task) => &task.status,
|
||||
Task::DkimKeyRotation(task) => &task.status,
|
||||
Task::DnsManagement(task) => &task.status,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +86,9 @@ impl Task {
|
||||
Task::AccountMaintenance(_) => Permission::TaskAccountMaintenance,
|
||||
Task::StoreMaintenance(_) => Permission::TaskStoreMaintenance,
|
||||
Task::SpamFilterMaintenance(_) => Permission::TaskSpamFilterMaintenance,
|
||||
Task::AcmeRenewal(_) => Permission::TaskAcmeRenewal,
|
||||
Task::DkimKeyRotation(_) => Permission::TaskDkimKeyRotation,
|
||||
Task::DnsManagement(_) => Permission::TaskDnsManagement,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user