Remove the last RefCell
@@ -136,7 +136,6 @@ use openmls_traits::{types::*, OpenMlsCryptoProvider};
use openmls_traits::crypto::OpenMlsCrypto;
use serde::{Deserialize, Serialize};
-use std::cell::RefCell;
use tls_codec::{TlsDeserialize, TlsSerialize, TlsSize};
// Public
@@ -546,7 +545,6 @@ impl EpochSecret {
}
/// The `EncryptionSecret` is used to create a `SecretTree`.
-#[derive(Serialize, Deserialize, Default)] // FIXME: what do we want serialization do here?
pub(crate) struct EncryptionSecret {
secret: Secret,
}
@@ -563,8 +561,7 @@ impl EncryptionSecret {
}
/// Create a `SecretTree` from the `encryption_secret` contained in the
- /// `EpochSecrets`. The `encryption_secret` is replaced with `None` in the
- /// process, allowing us to achieve FS.
+ /// `EpochSecrets`. The `encryption_secret` is consumed, allowing us to achieve FS.
pub(crate) fn create_secret_tree(self, treesize: LeafIndex) -> SecretTree {
SecretTree::new(self, treesize.into())
}
@@ -969,11 +966,10 @@ impl SenderDataSecret {
/// | `confirmation_key` | "confirm" |
/// | `membership_key` | "membership" |
/// | `resumption_secret` | "resumption" |
-#[derive(Serialize, Deserialize)]
pub(crate) struct EpochSecrets {
init_secret: Option<InitSecret>,
sender_data_secret: SenderDataSecret,
- encryption_secret: RefCell<EncryptionSecret>,
+ encryption_secret: EncryptionSecret,
exporter_secret: ExporterSecret,
authentication_secret: AuthenticationSecret,
external_secret: ExternalSecret,
@@ -1058,11 +1054,9 @@ impl EpochSecrets {
}
/// Encryption secret
- /// Note that this consumes the encryption secret.
- pub(crate) fn encryption_secret(&self) -> EncryptionSecret {
- // Note that we need to use a `RefCell` and not a `Cell` here because
- // we don't want to implement `Copy` for secrets.
- self.encryption_secret.take()
+ #[cfg(any(feature = "test-utils", test))]
+ pub(crate) fn encryption_secret(&self) -> &EncryptionSecret {
+ &self.encryption_secret
}
/// Derive `EpochSecrets` from an `EpochSecret`.
@@ -1101,7 +1095,7 @@ impl EpochSecrets {
Ok(EpochSecrets {
init_secret,
sender_data_secret,
- encryption_secret: RefCell::new(encryption_secret),
+ encryption_secret,
exporter_secret,
authentication_secret,
external_secret,
@@ -1120,11 +1114,10 @@ impl EpochSecrets {
serialized_context: Vec<u8>,
treesize: u32,
) -> (GroupEpochSecrets, MessageSecrets) {
- let secret_tree = self.encryption_secret().create_secret_tree(treesize);
+ let secret_tree = self.encryption_secret.create_secret_tree(treesize);
(
GroupEpochSecrets {
init_secret: self.init_secret,
- encryption_secret: self.encryption_secret,
exporter_secret: self.exporter_secret,
authentication_secret: self.authentication_secret,
external_secret: self.external_secret,
@@ -1144,7 +1137,6 @@ impl EpochSecrets {
#[derive(Serialize, Deserialize)]
pub(crate) struct GroupEpochSecrets {
init_secret: Option<InitSecret>,
- encryption_secret: RefCell<EncryptionSecret>,
exporter_secret: ExporterSecret,
authentication_secret: AuthenticationSecret,
external_secret: ExternalSecret,
