Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
beltram committed Feb 19, 2024
1 parent 378e2eb commit 174b08b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
11 changes: 10 additions & 1 deletion openmls/src/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Certificate {
///
/// This enum contains variants containing the different available credentials.
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
PartialEq, Eq, Clone, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
)]
#[repr(u8)]
pub enum MlsCredentialType {
Expand All @@ -239,6 +239,15 @@ pub enum MlsCredentialType {
X509(Certificate),
}

impl std::fmt::Debug for MlsCredentialType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
MlsCredentialType::Basic(c) => write!(f, "{c:?}"),
MlsCredentialType::X509(c) => write!(f, "{c:?}"),
}
}
}

/// Credential.
///
/// This struct contains MLS credential data, where the data depends on the
Expand Down
9 changes: 8 additions & 1 deletion openmls/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::{
fmt::Debug,
io::{Read, Write},
};
use std::fmt::Formatter;

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -221,11 +222,17 @@ pub enum Extension {
pub struct UnknownExtension(pub Vec<u8>);

/// A list of extensions with unique extension types.
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, tls_codec::TlsSize)]
#[derive(Default, Clone, PartialEq, Eq, Serialize, Deserialize, tls_codec::TlsSize)]
pub struct Extensions {
pub(crate) unique: Vec<Extension>,
}

impl std::fmt::Debug for Extensions {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.unique)
}
}

impl tls_codec::Serialize for Extensions {
fn tls_serialize<W: Write>(&self, writer: &mut W) -> Result<usize, tls_codec::Error> {
self.unique.tls_serialize(writer)
Expand Down
9 changes: 8 additions & 1 deletion openmls/src/extensions/ratchet_tree_extension.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Formatter;
use tls_codec::{TlsDeserialize, TlsSerialize, TlsSize};

use super::{Deserialize, Serialize};
Expand All @@ -13,12 +14,18 @@ use crate::treesync::{RatchetTree, RatchetTreeIn};
/// optional<Node> ratchet_tree<V>;
/// ```
#[derive(
PartialEq, Eq, Clone, Debug, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
PartialEq, Eq, Clone, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
)]
pub struct RatchetTreeExtension {
pub(crate) ratchet_tree: RatchetTreeIn,
}

impl std::fmt::Debug for RatchetTreeExtension {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.ratchet_tree)
}
}

impl RatchetTreeExtension {
/// Build a new extension from a vector of [`Node`](crate::treesync::node::Node)s.
pub fn new(ratchet_tree: RatchetTree) -> Self {
Expand Down
5 changes: 4 additions & 1 deletion openmls/src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ pub struct GroupId {

impl std::fmt::Debug for GroupId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode(self.value.as_slice()))
match std::str::from_utf8(self.value.as_slice()) {
Ok(id) => write!(f, "{id}"),
Err(_) => write!(f, "0x{}", hex::encode(self.value.as_slice())),
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion openmls/src/treesync/node/parent_node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This module contains the [`ParentNode`] struct, its implementation, as well
//! as the [`PlainUpdatePathNode`], a helper struct for the creation of
//! [`UpdatePathNode`] instances.
use std::fmt::Formatter;
use openmls_traits::{
types::{Ciphersuite, HpkeCiphertext},
OpenMlsCryptoProvider,
Expand Down Expand Up @@ -208,11 +209,17 @@ impl ParentNode {
}

/// A helper struct that maintains a sorted list of unmerged leaves.
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, TlsSize, TlsSerialize)]
#[derive(Eq, PartialEq, Clone, Serialize, Deserialize, TlsSize, TlsSerialize)]
pub(in crate::treesync) struct UnmergedLeaves {
list: Vec<LeafNodeIndex>,
}

impl std::fmt::Debug for UnmergedLeaves {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.list)
}
}

impl UnmergedLeaves {
pub(in crate::treesync) fn new() -> Self {
Self { list: Vec::new() }
Expand Down

0 comments on commit 174b08b

Please sign in to comment.