Skip to main content

SignatureAlgorithm

Trait SignatureAlgorithm 

Source
pub trait SignatureAlgorithm: Send + Sync {
    // Required methods
    fn algorithm_id(&self) -> &'static str;
    fn sign(&self, data: &[u8], private_key_pem: &str) -> Result<Vec<u8>>;
    fn verify(
        &self,
        data: &[u8],
        signature: &[u8],
        public_key_pem: &str,
    ) -> Result<()>;
    fn generate_keypair(&self) -> Result<(String, String)>;
    fn extract_public_key(&self, private_key_pem: &str) -> Result<String>;
}
Expand description

Trait for signature algorithms (strategy pattern)

This trait defines the interface for cryptographic signature operations, allowing different algorithms to be plugged in interchangeably.

Required Methods§

Source

fn algorithm_id(&self) -> &'static str

Returns the unique identifier for this algorithm (e.g., “RSA-SHA256”, “Ed25519”)

Source

fn sign(&self, data: &[u8], private_key_pem: &str) -> Result<Vec<u8>>

Sign data with the private key

Source

fn verify( &self, data: &[u8], signature: &[u8], public_key_pem: &str, ) -> Result<()>

Verify a signature against data and public key

Source

fn generate_keypair(&self) -> Result<(String, String)>

Generate a new key pair

§Returns

A tuple of (private_key_pem, public_key_pem)

Source

fn extract_public_key(&self, private_key_pem: &str) -> Result<String>

Extract the public key from a private key

Implementors§