use std::sync::Arc;
use rcgen::{
DistinguishedName, DnType, PKCS_ED25519, PublicKeyData, RemoteKeyPair, SignatureAlgorithm,
};
use crate::keys::Ed25519Identity;
pub(crate) struct IdentitySigner {
identity: Arc<Ed25519Identity>,
public_key: Vec<u8>,
}
impl IdentitySigner {
pub(crate) fn new(identity: Arc<Ed25519Identity>) -> Self {
let public_key = identity.public_key_bytes().to_vec();
Self {
identity,
public_key,
}
}
}
impl RemoteKeyPair for IdentitySigner {
fn public_key(&self) -> &[u8] {
&self.public_key
}
fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, rcgen::Error> {
Ok(self.identity.sign(msg).to_vec())
}
fn algorithm(&self) -> &'static SignatureAlgorithm {
&PKCS_ED25519
}
}
pub(crate) struct PresentedKey {
public_key: [u8; 32],
}
impl PresentedKey {
pub(crate) fn new(public_key: [u8; 32]) -> Self {
Self { public_key }
}
}
impl PublicKeyData for PresentedKey {
fn der_bytes(&self) -> &[u8] {
&self.public_key
}
fn algorithm(&self) -> &SignatureAlgorithm {
&PKCS_ED25519
}
}
pub(crate) fn distinguished_name(common_name: &str) -> DistinguishedName {
let mut dn = DistinguishedName::new();
dn.push(DnType::CommonName, common_name);
dn
}