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§
Sourcefn algorithm_id(&self) -> &'static str
fn algorithm_id(&self) -> &'static str
Returns the unique identifier for this algorithm (e.g., “RSA-SHA256”, “Ed25519”)
Sourcefn sign(&self, data: &[u8], private_key_pem: &str) -> Result<Vec<u8>>
fn sign(&self, data: &[u8], private_key_pem: &str) -> Result<Vec<u8>>
Sign data with the private key
Sourcefn verify(
&self,
data: &[u8],
signature: &[u8],
public_key_pem: &str,
) -> Result<()>
fn verify( &self, data: &[u8], signature: &[u8], public_key_pem: &str, ) -> Result<()>
Verify a signature against data and public key
Sourcefn generate_keypair(&self) -> Result<(String, String)>
fn generate_keypair(&self) -> Result<(String, String)>
Sourcefn extract_public_key(&self, private_key_pem: &str) -> Result<String>
fn extract_public_key(&self, private_key_pem: &str) -> Result<String>
Extract the public key from a private key