1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crateResult;
use RngCore;
/// Trait for types that can sign data.
///
/// This trait is implemented by all key types that support signing operations,
/// such as `Ed25519Key` and `EcdsaP256Key`. The `sign` method produces a
/// cryptographic signature of the message.
///
/// # Example
///
/// ```rust
/// use rust_bottle::signing::Sign;
/// use rust_bottle::keys::Ed25519Key;
/// use rand::rngs::OsRng;
///
/// let rng = &mut OsRng;
/// let key = Ed25519Key::generate(rng);
/// let message = b"Test message";
///
/// let signature = key.sign(rng, message).unwrap();
/// ```
/// Trait for types that can verify signatures.
///
/// This trait is implemented by all key types that support signature verification.
/// The `verify` method checks that a signature is valid for a given message.
///
/// # Example
///
/// ```rust
/// use rust_bottle::signing::{Sign, Verify};
/// use rust_bottle::keys::Ed25519Key;
/// use rand::rngs::OsRng;
///
/// let rng = &mut OsRng;
/// let key = Ed25519Key::generate(rng);
/// let message = b"Test message";
///
/// let signature = key.sign(rng, message).unwrap();
/// assert!(key.verify(message, &signature).is_ok());
/// ```
/// Generic sign function that works with any signer.
///
/// This is a convenience function that calls the `sign` method on any type
/// implementing the `Sign` trait.
///
/// # Arguments
///
/// * `rng` - A random number generator
/// * `signer` - A signer implementing the `Sign` trait
/// * `message` - The message to sign
///
/// # Returns
///
/// * `Ok(Vec<u8>)` - Signature bytes
/// * `Err(BottleError::VerifyFailed)` - If signing fails
/// Generic verify function that works with any verifier.
///
/// This is a convenience function that calls the `verify` method on any type
/// implementing the `Verify` trait.
///
/// # Arguments
///
/// * `verifier` - A verifier implementing the `Verify` trait
/// * `message` - The original message
/// * `signature` - The signature to verify
///
/// # Returns
///
/// * `Ok(())` - Signature is valid
/// * `Err(BottleError::VerifyFailed)` - If signature verification fails