|
1 | 1 | use errors::NewGroupError; |
2 | | -use openmls_traits::storage::StorageProvider as StorageProviderTrait; |
| 2 | +use openmls_traits::{crypto::OpenMlsCrypto, storage::StorageProvider as StorageProviderTrait}; |
3 | 3 |
|
4 | 4 | use super::{builder::MlsGroupBuilder, *}; |
5 | 5 | use crate::{ |
6 | 6 | credentials::CredentialWithKey, |
7 | 7 | extensions::Extensions, |
8 | 8 | group::{ |
9 | 9 | commit_builder::external_commits::ExternalCommitBuilder, |
10 | | - errors::{ExternalCommitError, WelcomeError}, |
| 10 | + errors::{ExportSecretError, ExternalCommitError, WelcomeError}, |
11 | 11 | }, |
12 | 12 | messages::{ |
13 | 13 | group_info::{GroupInfo, VerifiableGroupInfo}, |
@@ -583,6 +583,35 @@ impl StagedWelcome { |
583 | 583 | pub fn public_group(&self) -> &PublicGroup { |
584 | 584 | &self.public_group |
585 | 585 | } |
| 586 | + |
| 587 | + /// Exports a secret from the epoch of the group that is joined |
| 588 | + /// using this [`StagedWelcome`]. |
| 589 | + /// Returns [`ExportSecretError::KeyLengthTooLong`] if the requested |
| 590 | + /// key length is too long. |
| 591 | + pub fn export_secret<CryptoProvider: OpenMlsCrypto>( |
| 592 | + &self, |
| 593 | + crypto: &CryptoProvider, |
| 594 | + label: &str, |
| 595 | + context: &[u8], |
| 596 | + key_length: usize, |
| 597 | + ) -> Result<Vec<u8>, ExportSecretError> { |
| 598 | + if key_length > u16::MAX as usize { |
| 599 | + log::error!("Got a key that is larger than u16::MAX"); |
| 600 | + return Err(ExportSecretError::KeyLengthTooLong); |
| 601 | + } |
| 602 | + |
| 603 | + Ok(self |
| 604 | + .group_epoch_secrets |
| 605 | + .exporter_secret() |
| 606 | + .derive_exported_secret( |
| 607 | + self.group_context().ciphersuite(), |
| 608 | + crypto, |
| 609 | + label, |
| 610 | + context, |
| 611 | + key_length, |
| 612 | + ) |
| 613 | + .map_err(LibraryError::unexpected_crypto_error)?) |
| 614 | + } |
586 | 615 | } |
587 | 616 |
|
588 | 617 | fn keys_for_welcome<Provider: OpenMlsProvider>( |
|
0 commit comments