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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! # GREASE Support for MLS
//!
//! This module implements GREASE (Generate Random Extensions And Sustain
//! Extensibility) as defined in [RFC 9420 Section 13.5](https://www.rfc-editor.org/rfc/rfc9420.html#section-13.5).
//!
//! GREASE values are used to ensure that implementations properly handle
//! unknown values and maintain extensibility. The GREASE values follow a
//! specific pattern where both bytes are of the form `0x_A` (e.g., 0x0A0A,
//! 0x1A1A, 0x2A2A, etc.).
//!
//! ## Purpose
//!
//! GREASE helps prevent extensibility failures by:
//! - Ensuring implementations don't reject unknown values
//! - Testing that parsers properly handle unexpected values
//! - Maintaining forward compatibility
//!
//! ## Usage in OpenMLS
//!
//! OpenMLS provides tools for working with GREASE values:
//!
//! - **Recognition**: GREASE values are automatically recognized during
//! deserialization and stored in dedicated `Grease` variants (e.g.,
//! `ProposalType::Grease`, `ExtensionType::Grease`).
//!
//! - **Validation**: During capability validation, GREASE values are treated
//! the same as unknown values and filtered out appropriately.
//!
//! - **Injection**: Library users can inject random GREASE values into
//! capabilities using the [`Capabilities::with_grease`](crate::treesync::node::leaf_node::Capabilities::with_grease)
//! method or by manually adding `Grease` variants.
//!
//! ## Example
//!
//! ```
//! use openmls::prelude::*;
//! use openmls_rust_crypto::OpenMlsRustCrypto;
//!
//! let provider = OpenMlsRustCrypto::default();
//!
//! // Inject random GREASE values into capabilities
//! let capabilities = Capabilities::builder()
//! .with_grease(provider.rand())
//! .build();
//!
//! // Capabilities now contain random GREASE values
//! assert!(capabilities.ciphersuites().iter().any(|cs| cs.is_grease()));
//! ```
use OpenMlsRand;
// Re-export GREASE constants and functions from traits crate
pub use ;
/// Returns a random GREASE value from the set of valid GREASE values.
///
/// This function uses the provided random number generator to select one of the
/// 15 valid GREASE values defined in RFC 9420.
///
/// # Arguments
///
/// * `rand` - A random number generator implementing [`OpenMlsRand`]
///
/// # Returns
///
/// A randomly selected GREASE value
///
/// # Examples
///
/// ```
/// use openmls::grease::random_grease_value;
/// use openmls_rust_crypto::RustCrypto;
///
/// let crypto = RustCrypto::default();
/// let grease = random_grease_value(&crypto);
/// assert!(openmls::grease::is_grease_value(grease));
/// ```