From 174b08b937a624d31280f60b7d4c2ebfde433827 Mon Sep 17 00:00:00 2001 From: beltram Date: Mon, 19 Feb 2024 18:34:26 +0100 Subject: [PATCH] better --- openmls/src/credentials/mod.rs | 11 ++++++++++- openmls/src/extensions/mod.rs | 9 ++++++++- openmls/src/extensions/ratchet_tree_extension.rs | 9 ++++++++- openmls/src/group/mod.rs | 5 ++++- openmls/src/treesync/node/parent_node.rs | 9 ++++++++- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/openmls/src/credentials/mod.rs b/openmls/src/credentials/mod.rs index bb99db29eb..c92b98b61c 100644 --- a/openmls/src/credentials/mod.rs +++ b/openmls/src/credentials/mod.rs @@ -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 { @@ -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 diff --git a/openmls/src/extensions/mod.rs b/openmls/src/extensions/mod.rs index 7beacd2074..d1f473dd8f 100644 --- a/openmls/src/extensions/mod.rs +++ b/openmls/src/extensions/mod.rs @@ -23,6 +23,7 @@ use std::{ fmt::Debug, io::{Read, Write}, }; +use std::fmt::Formatter; use serde::{Deserialize, Serialize}; @@ -221,11 +222,17 @@ pub enum Extension { pub struct UnknownExtension(pub Vec); /// 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, } +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(&self, writer: &mut W) -> Result { self.unique.tls_serialize(writer) diff --git a/openmls/src/extensions/ratchet_tree_extension.rs b/openmls/src/extensions/ratchet_tree_extension.rs index 21f5aef9ba..a0d49ba4cd 100644 --- a/openmls/src/extensions/ratchet_tree_extension.rs +++ b/openmls/src/extensions/ratchet_tree_extension.rs @@ -1,3 +1,4 @@ +use std::fmt::Formatter; use tls_codec::{TlsDeserialize, TlsSerialize, TlsSize}; use super::{Deserialize, Serialize}; @@ -13,12 +14,18 @@ use crate::treesync::{RatchetTree, RatchetTreeIn}; /// optional ratchet_tree; /// ``` #[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 { diff --git a/openmls/src/group/mod.rs b/openmls/src/group/mod.rs index d67b505ae0..fc18978256 100644 --- a/openmls/src/group/mod.rs +++ b/openmls/src/group/mod.rs @@ -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())), + } } } diff --git a/openmls/src/treesync/node/parent_node.rs b/openmls/src/treesync/node/parent_node.rs index 0f74af8ed2..1e2ae13608 100644 --- a/openmls/src/treesync/node/parent_node.rs +++ b/openmls/src/treesync/node/parent_node.rs @@ -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, @@ -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, } +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() }