refactor: Change config private key type to K256Secret

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-23 22:20:50 +03:00
parent 672d7a2d3c
commit bd45d6e1a9
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
3 changed files with 24 additions and 8 deletions

View file

@ -25,10 +25,7 @@
pub(crate) mod server {
use std::net::{IpAddr, Ipv4Addr};
use oxidetalis_core::{
cipher::K256Secret,
types::{PrivateKey, Size},
};
use oxidetalis_core::{cipher::K256Secret, types::Size};
pub fn name() -> String {
"example.com".to_owned()
@ -39,8 +36,8 @@ pub(crate) mod server {
pub const fn port() -> u16 {
7294
}
pub fn private_key() -> PrivateKey {
K256Secret::new().privkey()
pub fn private_key() -> K256Secret {
K256Secret::new()
}
pub const fn nonce_cache_size() -> Size {
Size::MB(1)

View file

@ -23,7 +23,7 @@
use std::{fs, io::Error as IoError, net::IpAddr, path::Path};
use derivative::Derivative;
use oxidetalis_core::types::{PrivateKey, Size};
use oxidetalis_core::{cipher::K256Secret, types::Size};
use serde::{Deserialize, Serialize};
use toml::{de::Error as TomlDeError, ser::Error as TomlSerError};
@ -66,7 +66,7 @@ pub struct Server {
pub port: u16,
/// Server keypair
#[derivative(Default(value = "defaults::server::private_key()"))]
pub private_key: PrivateKey,
pub private_key: K256Secret,
/// Nonce cache limit
#[derivative(Default(value = "defaults::server::nonce_cache_size()"))]
pub nonce_cache_size: Size,

View file

@ -25,6 +25,7 @@ use base58::FromBase58;
use serde::{de::Error as DeError, Deserialize, Serialize};
use super::{PrivateKey, PublicKey, Signature};
use crate::cipher::K256Secret;
impl<'de> Deserialize<'de> for PrivateKey {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@ -99,3 +100,21 @@ impl Serialize for Signature {
serializer.serialize_str(self.to_string().as_str())
}
}
impl Serialize for K256Secret {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
PrivateKey::serialize(&self.privkey(), serializer)
}
}
impl<'de> Deserialize<'de> for K256Secret {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Ok(Self::from_privkey(&PrivateKey::deserialize(deserializer)?))
}
}