Skip to content

Commit

Permalink
make public struct internal members public too
Browse files Browse the repository at this point in the history
  • Loading branch information
rainliu committed Sep 2, 2023
1 parent 1400571 commit fb168c1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 49 deletions.
17 changes: 17 additions & 0 deletions rmls/src/crypto/cipher_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ impl Display for CipherSuite {
/// used in a leaf node in the tree to indicate an individual client's CipherSuite Capability.
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct CipherSuiteCapability(pub(crate) u16);

impl TryFrom<CipherSuiteCapability> for CipherSuite {
type Error = Error;

fn try_from(c: CipherSuiteCapability) -> std::result::Result<Self, Self::Error> {
match c.0 {
0x0001 => Ok(CipherSuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519),
0x0002 => Ok(CipherSuite::MLS_128_DHKEMP256_AES128GCM_SHA256_P256),
0x0003 => Ok(CipherSuite::MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519),
0x0004 => Ok(CipherSuite::MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448),
0x0005 => Ok(CipherSuite::MLS_256_DHKEMP521_AES256GCM_SHA512_P521),
0x0006 => Ok(CipherSuite::MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448),
0x0007 => Ok(CipherSuite::MLS_256_DHKEMP384_AES256GCM_SHA384_P384),
_ => Err(Error::InvalidCipherSuiteValue(c.0)),
}
}
}
58 changes: 29 additions & 29 deletions rmls/src/framing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,10 @@ impl AuthenticatedContent {
/// [RFC9420 Sec.6.1](https://www.rfc-editor.org/rfc/rfc9420.html#section-6.1) FramedContentTBS
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct FramedContentTBS {
version: ProtocolVersion,
wire_format: WireFormat,
content: FramedContent,
context: Option<GroupContext>, // for SenderType::Member and SenderType::NewMemberCommit
pub version: ProtocolVersion,
pub wire_format: WireFormat,
pub content: FramedContent,
pub context: Option<GroupContext>, // for SenderType::Member and SenderType::NewMemberCommit
}

impl Deserializer for FramedContentTBS {
Expand Down Expand Up @@ -703,8 +703,8 @@ impl Serializer for FramedContentTBS {
/// is used for authenticating FramedContent
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct FramedContentAuthData {
signature: Bytes,
pub(crate) confirmation_tag: Bytes, // for ContentType::Commit
pub signature: Bytes,
pub confirmation_tag: Bytes, // for ContentType::Commit
}

impl FramedContentAuthData {
Expand Down Expand Up @@ -801,9 +801,9 @@ impl FramedContentAuthData {
/// authenticated but not encrypted are encoded using the PublicMessage structure.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct PublicMessage {
pub(crate) content: FramedContent,
auth: FramedContentAuthData,
membership_tag: Option<Bytes>, // for SenderType::Member
pub content: FramedContent,
pub auth: FramedContentAuthData,
pub membership_tag: Option<Bytes>, // for SenderType::Member
}

impl Deserializer for PublicMessage {
Expand Down Expand Up @@ -950,8 +950,8 @@ impl PublicMessage {
/// by members, it MUST be set to AuthenticatedContentTBM
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct AuthenticatedContentTBM {
content_tbs: FramedContentTBS,
auth: FramedContentAuthData,
pub content_tbs: FramedContentTBS,
pub auth: FramedContentAuthData,
}

impl Deserializer for AuthenticatedContentTBM {
Expand Down Expand Up @@ -983,12 +983,12 @@ impl Serializer for AuthenticatedContentTBM {
/// encrypted messages are encoded using the PrivateMessage structure.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct PrivateMessage {
group_id: GroupID,
epoch: u64,
pub(crate) content_type: ContentType,
authenticated_data: Bytes,
encrypted_sender_data: Bytes,
ciphertext: Bytes,
pub group_id: GroupID,
pub epoch: u64,
pub content_type: ContentType,
pub authenticated_data: Bytes,
pub encrypted_sender_data: Bytes,
pub ciphertext: Bytes,
}

impl Deserializer for PrivateMessage {
Expand Down Expand Up @@ -1165,8 +1165,8 @@ impl PrivateMessage {
/// encrypted is encoded in a PrivateMessageContent structure.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct PrivateMessageContent {
pub(crate) content: Content,
auth: FramedContentAuthData,
pub content: Content,
pub auth: FramedContentAuthData,
}

impl PrivateMessageContent {
Expand Down Expand Up @@ -1214,10 +1214,10 @@ impl Serializer for PrivateMessageContent {
/// with the values used to identify the key and nonce
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct PrivateContentAAD {
group_id: GroupID,
epoch: u64,
content_type: ContentType,
authenticated_data: Bytes,
pub group_id: GroupID,
pub epoch: u64,
pub content_type: ContentType,
pub authenticated_data: Bytes,
}

impl Deserializer for PrivateContentAAD {
Expand Down Expand Up @@ -1262,9 +1262,9 @@ impl Serializer for PrivateContentAAD {
/// Before being encrypted, the sender data is encoded as an object of the following form
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct SenderData {
leaf_index: LeafIndex,
pub(crate) generation: u32,
pub(crate) reuse_guard: [u8; 4],
pub leaf_index: LeafIndex,
pub generation: u32,
pub reuse_guard: [u8; 4],
}

impl SenderData {
Expand Down Expand Up @@ -1319,9 +1319,9 @@ impl Serializer for SenderData {
/// SenderData ciphertext is the first three fields of PrivateMessage.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct SenderDataAAD {
group_id: GroupID,
epoch: u64,
content_type: ContentType,
pub group_id: GroupID,
pub epoch: u64,
pub content_type: ContentType,
}

impl Serializer for SenderDataAAD {
Expand Down
2 changes: 1 addition & 1 deletion rmls/src/group/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bytes::{Buf, BufMut, Bytes};
// http://www.iana.org/assignments/mls/mls.xhtml#mls-proposal-types
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u16)]
pub(crate) enum ProposalTypeCapability {
pub enum ProposalTypeCapability {
#[default]
Add = 0x0001,
Update = 0x0002,
Expand Down
37 changes: 18 additions & 19 deletions rmls/src/ratchet_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ impl Serializer for LeafNodeSource {
/// [RFC9420 Sec.7.2](https://www.rfc-editor.org/rfc/rfc9420.html#section-7.2) Capabilities
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct Capabilities {
versions: Vec<ProtocolVersion>,
cipher_suites: Vec<CipherSuiteCapability>,
extensions: Vec<ExtensionType>,
proposals: Vec<ProposalTypeCapability>,
pub(crate) credentials: Vec<CredentialType>,
pub versions: Vec<ProtocolVersion>,
pub cipher_suites: Vec<CipherSuiteCapability>,
pub extensions: Vec<ExtensionType>,
pub proposals: Vec<ProposalTypeCapability>,
pub credentials: Vec<CredentialType>,
}

impl Deserializer for Capabilities {
Expand Down Expand Up @@ -303,8 +303,8 @@ const MAX_LEAF_NODE_LIFETIME: Duration = Duration::from_secs(3 * 30 * 24);
/// [RFC9420 Sec.7.2](https://www.rfc-editor.org/rfc/rfc9420.html#section-7.2) Lifetime
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct Lifetime {
not_before: u64,
not_after: u64,
pub not_before: u64,
pub not_after: u64,
}

impl Deserializer for Lifetime {
Expand Down Expand Up @@ -408,8 +408,8 @@ impl From<ExtensionType> for u16 {
/// [RFC9420 Sec.7.2](https://www.rfc-editor.org/rfc/rfc9420.html#section-7.2) Extension
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct Extension {
extension_type: ExtensionType,
extension_data: Bytes,
pub extension_type: ExtensionType,
pub extension_data: Bytes,
}

/// [RFC9420 Sec.7.2](https://www.rfc-editor.org/rfc/rfc9420.html#section-7.2) Extensions
Expand Down Expand Up @@ -462,14 +462,13 @@ impl Extensions {
/// [RFC9420 Sec.7.2](https://www.rfc-editor.org/rfc/rfc9420.html#section-7.2) LeafNode
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct LeafNode {
pub(crate) encryption_key: HPKEPublicKey,
pub(crate) signature_key: SignaturePublicKey,
credential: Credential,
pub(crate) capabilities: Capabilities,
pub(crate) leaf_node_source: LeafNodeSource,
extensions: Extensions,

signature: Bytes,
pub encryption_key: HPKEPublicKey,
pub signature_key: SignaturePublicKey,
pub credential: Credential,
pub capabilities: Capabilities,
pub leaf_node_source: LeafNodeSource,
pub extensions: Extensions,
pub signature: Bytes,
}

impl LeafNode {
Expand Down Expand Up @@ -741,8 +740,8 @@ impl Serializer for UpdatePathNode {
/// as the filtered direct path.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct UpdatePath {
pub(crate) leaf_node: LeafNode,
pub(crate) nodes: Vec<UpdatePathNode>,
pub leaf_node: LeafNode,
pub nodes: Vec<UpdatePathNode>,
}

impl Deserializer for UpdatePath {
Expand Down

0 comments on commit fb168c1

Please sign in to comment.