oxicrypto_core/traits/sig.rs
1use alloc::vec::Vec;
2
3use crate::{CryptoError, KeyPair, SecretVec};
4
5/// Asymmetric signing operation.
6pub trait Signer: Send + Sync {
7 /// Human-readable algorithm identifier (e.g. `"Ed25519"`).
8 #[must_use]
9 fn name(&self) -> &'static str;
10 /// Fixed signature length in bytes.
11 #[must_use]
12 fn signature_len(&self) -> usize;
13 /// Sign `msg` with `sk` (raw secret-key bytes) and write the signature
14 /// into `sig_out`.
15 ///
16 /// Returns the number of bytes written.
17 #[must_use = "result must be checked"]
18 fn sign(&self, sk: &[u8], msg: &[u8], sig_out: &mut [u8]) -> Result<usize, CryptoError>;
19}
20
21/// Asymmetric signature verification.
22pub trait Verifier: Send + Sync {
23 /// Human-readable algorithm identifier (e.g. `"Ed25519"`).
24 #[must_use]
25 fn name(&self) -> &'static str;
26 /// Verify `sig` over `msg` with `pk` (raw public-key bytes).
27 ///
28 /// Returns [`CryptoError::InvalidTag`] on verification failure.
29 #[must_use = "result must be checked"]
30 fn verify(&self, pk: &[u8], msg: &[u8], sig: &[u8]) -> Result<(), CryptoError>;
31}
32
33/// Key pair generator for asymmetric algorithms.
34pub trait KeyGenerator: Send + Sync {
35 /// Human-readable algorithm identifier (e.g. `"Ed25519"`).
36 #[must_use]
37 fn name(&self) -> &'static str;
38 /// Generate a fresh key pair.
39 ///
40 /// Returns `(secret_key, public_key)` wrapped in [`KeyPair`].
41 /// The secret half uses [`SecretVec`] (auto-zeroized on drop).
42 #[must_use = "result must be checked"]
43 fn generate_keypair(&self) -> Result<KeyPair<SecretVec, Vec<u8>>, CryptoError>;
44}