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§
Sourcetype SigningKey
type SigningKey
The type of the signing key
Sourcetype VerifyingKey
type VerifyingKey
The type of the verifying key
Required Methods§
Sourcefn sign_hash(
hash: &str,
private_key: &Self::SigningKey,
) -> Result<String, CryptoError>
fn sign_hash( hash: &str, private_key: &Self::SigningKey, ) -> Result<String, CryptoError>
Sourcefn verify_signature(
hash: &str,
signature: &str,
public_key: &Self::VerifyingKey,
) -> Result<bool, CryptoError>
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 verifypublic_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.