Skip to content

Commit

Permalink
remove Metadata extension in favour of using Unknown extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Jan 29, 2024
1 parent 305b761 commit 17989cf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
5 changes: 0 additions & 5 deletions openmls/src/extensions/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ impl Size for Extension {
Extension::ExternalSenders(e) => e.tls_serialized_len(),
Extension::LastResort(e) => e.tls_serialized_len(),
Extension::ImmutableMetadata(e) => e.tls_serialized_len(),
Extension::Metadata(e) => e.tls_serialized_len(),
Extension::Unknown(_, e) => e.0.len(),
};

Expand Down Expand Up @@ -72,7 +71,6 @@ impl Serialize for Extension {
Extension::ExternalSenders(e) => e.tls_serialize(&mut extension_data),
Extension::LastResort(e) => e.tls_serialize(&mut extension_data),
Extension::ImmutableMetadata(e) => e.tls_serialize(&mut extension_data),
Extension::Metadata(e) => e.tls_serialize(&mut extension_data),
Extension::Unknown(_, e) => extension_data
.write_all(e.0.as_slice())
.map(|_| e.0.len())
Expand Down Expand Up @@ -125,9 +123,6 @@ impl Deserialize for Extension {
ExtensionType::ImmutableMetadata => {
Extension::ImmutableMetadata(Metadata::tls_deserialize(&mut extension_data)?)
}
ExtensionType::Metadata => {
Extension::Metadata(Metadata::tls_deserialize(&mut extension_data)?)
}
ExtensionType::Unknown(unknown) => {
Extension::Unknown(unknown, UnknownExtension(extension_data.to_vec()))
}
Expand Down
19 changes: 0 additions & 19 deletions openmls/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ pub enum ExtensionType {
/// This can only be set on creation of the group.
ImmutableMetadata,

/// Metadata extension for policies and other metadata. GroupContext Extension.
Metadata,

/// A currently unknown extension type.
Unknown(u16),
}
Expand Down Expand Up @@ -159,7 +156,6 @@ impl From<u16> for ExtensionType {
5 => ExtensionType::ExternalSenders,
10 => ExtensionType::LastResort,
0xf000 => ExtensionType::ImmutableMetadata,
0xf001 => ExtensionType::Metadata,
unknown => ExtensionType::Unknown(unknown),
}
}
Expand All @@ -175,7 +171,6 @@ impl From<ExtensionType> for u16 {
ExtensionType::ExternalSenders => 5,
ExtensionType::LastResort => 10,
ExtensionType::ImmutableMetadata => 0xf000,
ExtensionType::Metadata => 0xf001,
ExtensionType::Unknown(unknown) => unknown,
}
}
Expand All @@ -193,7 +188,6 @@ impl ExtensionType {
| ExtensionType::ExternalSenders
| ExtensionType::LastResort
| ExtensionType::ImmutableMetadata
| ExtensionType::Metadata
)
}
}
Expand Down Expand Up @@ -235,9 +229,6 @@ pub enum Extension {
/// An [`ImmutableMetadata`] extension
ImmutableMetadata(Metadata),

// A [`Metadata`] extension
Metadata(Metadata),

/// A currently unknown extension.
Unknown(u16, UnknownExtension),
}
Expand Down Expand Up @@ -437,15 +428,6 @@ impl Extensions {
_ => None,
})
}

/// Get a reference to the mutable [`Metadata`] if there is any.
pub fn metadata(&self) -> Option<&Metadata> {
self.find_by_type(ExtensionType::Metadata)
.and_then(|e| match e {
Extension::Metadata(e) => Some(e),
_ => None,
})
}
}

impl Extension {
Expand Down Expand Up @@ -536,7 +518,6 @@ impl Extension {
Extension::ExternalSenders(_) => ExtensionType::ExternalSenders,
Extension::LastResort(_) => ExtensionType::LastResort,
Extension::ImmutableMetadata(_) => ExtensionType::ImmutableMetadata,
Extension::Metadata(_) => ExtensionType::Metadata,
Extension::Unknown(kind, _) => ExtensionType::Unknown(*kind),
}
}
Expand Down
10 changes: 7 additions & 3 deletions openmls/src/extensions/test_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn test_metadata(ciphersuite: Ciphersuite, provider: &impl OpenMlsProvider) {

// example metadata (opaque data -- test hex string is "1cedc0ffee")
let metadata = vec![0x1c, 0xed, 0xc0, 0xff, 0xee];
let ext = Extension::Metadata(Metadata::new(metadata.clone()));
let ext = Extension::Unknown(0xf001, UnknownExtension(metadata.clone()));
let extensions = Extensions::from_vec(vec![ext]).expect("could not build extensions struct");

let config = MlsGroupCreateConfig::builder()
Expand All @@ -284,10 +284,14 @@ fn test_metadata(ciphersuite: Ciphersuite, provider: &impl OpenMlsProvider) {
let got_metadata = alice_group
.export_group_context()
.extensions()
.metadata()
.find_by_type(ExtensionType::Unknown(0xf001))
.expect("failed to read group metadata");

assert_eq!(got_metadata.metadata(), &metadata);
if let Extension::Unknown(0xf001, UnknownExtension(got_metadata)) = got_metadata {
assert_eq!(got_metadata, &metadata);
} else {
panic!("metadata extension has wrong extension enum variant")
}
}

#[apply(ciphersuites_and_providers)]
Expand Down

0 comments on commit 17989cf

Please sign in to comment.