SignatureAlgorithm

Trait SignatureAlgorithm 

Source
pub trait SignatureAlgorithm: Sealed {
    type SigningKey;
    type VerifyingKey;
    type Signature;

    // Required methods
    fn sign_hash(
        hash: &str,
        private_key: &Self::SigningKey,
    ) -> Result<String, CryptoError>;
    fn verify_signature(
        hash: &str,
        signature: &str,
        public_key: &Self::VerifyingKey,
    ) -> Result<bool, CryptoError>;
}
Expand description

Core trait for signature algorithms used in sentinel-crypto. This trait abstracts digital signature operations to allow easy switching between different signature schemes while maintaining a consistent interface.

Design choice: Associated types for key types ensure type safety at compile-time. The trait is sealed to prevent insecure external implementations. All operations return our unified CryptoError for consistent error handling.

Required Associated Types§

Source

type SigningKey

The type of the signing key

Source

type VerifyingKey

The type of the verifying key

Source

type Signature

The type of the signature

Required Methods§

Source

fn sign_hash( hash: &str, private_key: &Self::SigningKey, ) -> Result<String, CryptoError>

Signs the given hash using the provided private key. Returns a hex-encoded signature string.

§Arguments
  • hash - The hash to sign (as a string)
  • private_key - The signing key
§Returns

A hex-encoded signature string

§Errors

Returns CryptoError::Signature if signing fails

Source

fn verify_signature( hash: &str, signature: &str, public_key: &Self::VerifyingKey, ) -> Result<bool, CryptoError>

Verifies a signature against the given hash using the provided public key.

§Arguments
  • hash - The original hash (as a string)
  • signature - The hex-encoded signature to verify
  • public_key - The verifying key
§Returns

true if verification succeeds, false otherwise

§Errors

Returns CryptoError if verification process fails

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§