| 1 |
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
// Copyright by contributors to this project. |
| 3 |
// SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 4 |
|
| 5 |
pub use mls_rs_core::extension::{ExtensionType, MlsCodecExtension, MlsExtension}; |
| 6 |
|
| 7 |
pub(crate) use built_in::*; |
| 8 |
#[cfg(feature = "last_resort_key_package_ext")] |
| 9 |
pub(crate) use recommended::*; |
| 10 |
|
| 11 |
/// Default extension types required by the MLS RFC. |
| 12 |
pub mod built_in; |
| 13 |
|
| 14 |
/// Extension types which are not mandatory, but still recommended. |
| 15 |
#[cfg(feature = "last_resort_key_package_ext")] |
| 16 |
pub mod recommended; |
| 17 |
|
| 18 |
#[cfg(test)] |
| 19 |
pub(crate) mod test_utils { |
| 20 |
use alloc::vec::Vec; |
| 21 |
use core::convert::Infallible; |
| 22 |
use core::fmt::Debug; |
| 23 |
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize}; |
| 24 |
use mls_rs_core::extension::MlsExtension; |
| 25 |
|
| 26 |
use super::*; |
| 27 |
|
| 28 |
pub const TEST_EXTENSION_TYPE: u16 = 42; |
| 29 |
|
| 30 |
#[derive(MlsSize, MlsEncode, MlsDecode, Clone, Debug, PartialEq)] |
| 31 |
pub(crate) struct TestExtension { |
| 32 |
pub(crate) foo: u8, |
| 33 |
} |
| 34 |
|
| 35 |
impl From<u8> for TestExtension { |
| 36 |
fn from(value: u8) -> Self { |
| 37 |
Self { foo: value } |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
impl MlsExtension for TestExtension { |
| 42 |
type SerializationError = Infallible; |
| 43 |
|
| 44 |
type DeserializationError = Infallible; |
| 45 |
|
| 46 |
fn extension_type() -> ExtensionType { |
| 47 |
ExtensionType::from(TEST_EXTENSION_TYPE) |
| 48 |
} |
| 49 |
|
| 50 |
fn to_bytes(&self) -> Result<Vec<u8>, Self::SerializationError> { |
| 51 |
Ok([self.foo].to_vec()) |
| 52 |
} |
| 53 |
|
| 54 |
fn from_bytes(data: &[u8]) -> Result<Self, Self::DeserializationError> { |
| 55 |
Ok(TestExtension { foo: data[0] }) |
| 56 |
} |
| 57 |
} |
| 58 |
} |