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 9 /// Default extension types required by the MLS RFC. 10 pub mod built_in; 11 12 #[cfg(test)] 13 pub(crate) mod test_utils { 14 use alloc::vec::Vec; 15 use core::convert::Infallible; 16 use core::fmt::Debug; 17 use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize}; 18 use mls_rs_core::extension::MlsExtension; 19 20 use super::*; 21 22 pub const TEST_EXTENSION_TYPE: u16 = 42; 23 24 #[derive(MlsSize, MlsEncode, MlsDecode, Clone, Debug, PartialEq)] 25 pub(crate) struct TestExtension { 26 pub(crate) foo: u8, 27 } 28 29 impl From<u8> for TestExtension { from(value: u8) -> Self30 fn from(value: u8) -> Self { 31 Self { foo: value } 32 } 33 } 34 35 impl MlsExtension for TestExtension { 36 type SerializationError = Infallible; 37 38 type DeserializationError = Infallible; 39 extension_type() -> ExtensionType40 fn extension_type() -> ExtensionType { 41 ExtensionType::from(TEST_EXTENSION_TYPE) 42 } 43 to_bytes(&self) -> Result<Vec<u8>, Self::SerializationError>44 fn to_bytes(&self) -> Result<Vec<u8>, Self::SerializationError> { 45 Ok([self.foo].to_vec()) 46 } 47 from_bytes(data: &[u8]) -> Result<Self, Self::DeserializationError>48 fn from_bytes(data: &[u8]) -> Result<Self, Self::DeserializationError> { 49 Ok(TestExtension { foo: data[0] }) 50 } 51 } 52 } 53