summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Geisler <mgeisler@google.com>2024-04-26 14:31:30 +0200
committerMartin Geisler <mgeisler@google.com>2024-04-26 14:31:31 +0200
commit4131e9756c9a0d0fd1dd625af796c825d900d3cf (patch)
tree124a3a91b02ceffa81377a1a07589cc115c7ddfc
parent18bbccad845249f347f8ebc916a3040bfac69054 (diff)
downloadmls-rs-core-4131e9756c9a0d0fd1dd625af796c825d900d3cf.tar.gz
Upgrade mls-rs-core to 0.18.0
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update external/rust/crates/mls-rs-core For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: Ifa10caf842735ac8232ab6bdf9a3c8c864b9d1b8
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp7
-rw-r--r--Cargo.lock665
-rw-r--r--Cargo.toml26
-rw-r--r--METADATA22
-rw-r--r--patches/add-license-files.patch204
-rw-r--r--src/crypto.rs82
-rw-r--r--src/crypto/cipher_suite.rs1
-rw-r--r--src/debug.rs130
-rw-r--r--src/extension.rs22
-rw-r--r--src/extension/list.rs1
-rw-r--r--src/group/group_state.rs60
-rw-r--r--src/group/proposal_type.rs1
-rw-r--r--src/group/roster.rs1
-rw-r--r--src/identity/basic.rs17
-rw-r--r--src/identity/credential.rs20
-rw-r--r--src/identity/signing_identity.rs1
-rw-r--r--src/identity/x509.rs19
-rw-r--r--src/key_package.rs19
-rw-r--r--src/lib.rs40
-rw-r--r--src/protocol_version.rs1
-rw-r--r--src/psk.rs39
-rw-r--r--src/secret.rs13
-rw-r--r--src/time.rs1
24 files changed, 663 insertions, 731 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 2c26ae7..ae313fe 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "105faf3f0a4270ef4381d82fe0f88f1d396e67e1"
+ "sha1": "d54563f15579db6482817d2e3dbdcbc10957908c"
},
"path_in_vcs": "mls-rs-core"
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index 7829b4c..7593591 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,5 +1,7 @@
// This file is generated by cargo_embargo.
-// Do not modify this file as changes will be overridden on upgrade.
+// Do not modify this file after the first "rust_*" or "genrule" module
+// because the changes will be overridden on upgrade.
+// Content before the first "rust_*" or "genrule" module is preserved.
// TODO: Add license.
rust_library {
@@ -7,7 +9,7 @@ rust_library {
host_supported: true,
crate_name: "mls_rs_core",
cargo_env_compat: true,
- cargo_pkg_version: "0.17.1",
+ cargo_pkg_version: "0.18.0",
srcs: ["src/lib.rs"],
edition: "2021",
features: [
@@ -18,6 +20,7 @@ rust_library {
"x509",
],
rustlibs: [
+ "libhex",
"libmls_rs_codec",
"libthiserror",
"libzeroize",
diff --git a/Cargo.lock b/Cargo.lock
deleted file mode 100644
index 73020dc..0000000
--- a/Cargo.lock
+++ /dev/null
@@ -1,665 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 3
-
-[[package]]
-name = "arbitrary"
-version = "1.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
-dependencies = [
- "derive_arbitrary",
-]
-
-[[package]]
-name = "assert_matches"
-version = "1.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
-
-[[package]]
-name = "async-trait"
-version = "0.1.77"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "bumpalo"
-version = "3.15.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3b1be7772ee4501dba05acbe66bb1e8760f6a6c474a36035631638e4415f130"
-
-[[package]]
-name = "cfg-if"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-
-[[package]]
-name = "console_error_panic_hook"
-version = "0.1.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
-dependencies = [
- "cfg-if",
- "wasm-bindgen",
-]
-
-[[package]]
-name = "critical-section"
-version = "1.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216"
-
-[[package]]
-name = "darling"
-version = "0.20.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955"
-dependencies = [
- "darling_core",
- "darling_macro",
-]
-
-[[package]]
-name = "darling_core"
-version = "0.20.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855"
-dependencies = [
- "fnv",
- "ident_case",
- "proc-macro2",
- "quote",
- "strsim",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "darling_macro"
-version = "0.20.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be"
-dependencies = [
- "darling_core",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "derive_arbitrary"
-version = "1.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "either"
-version = "1.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
-
-[[package]]
-name = "ext-trait"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d772df1c1a777963712fb68e014235e80863d6a91a85c4e06ba2d16243a310e5"
-dependencies = [
- "ext-trait-proc_macros",
-]
-
-[[package]]
-name = "ext-trait-proc_macros"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ab7934152eaf26aa5aa9f7371408ad5af4c31357073c9e84c3b9d7f11ad639a"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
-
-[[package]]
-name = "extension-traits"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a296e5a895621edf9fa8329c83aa1cb69a964643e36cf54d8d7a69b789089537"
-dependencies = [
- "ext-trait",
-]
-
-[[package]]
-name = "fnv"
-version = "1.0.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
-
-[[package]]
-name = "heck"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
-
-[[package]]
-name = "hex"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
-dependencies = [
- "serde",
-]
-
-[[package]]
-name = "ident_case"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
-
-[[package]]
-name = "itertools"
-version = "0.12.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
-dependencies = [
- "either",
-]
-
-[[package]]
-name = "itoa"
-version = "1.0.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
-
-[[package]]
-name = "js-sys"
-version = "0.3.68"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
-dependencies = [
- "wasm-bindgen",
-]
-
-[[package]]
-name = "libc"
-version = "0.2.153"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
-
-[[package]]
-name = "log"
-version = "0.4.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
-
-[[package]]
-name = "macro_rules_attribute"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf0c9b980bf4f3a37fd7b1c066941dd1b1d0152ce6ee6e8fe8c49b9f6810d862"
-dependencies = [
- "macro_rules_attribute-proc_macro",
- "paste",
-]
-
-[[package]]
-name = "macro_rules_attribute-proc_macro"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58093314a45e00c77d5c508f76e77c3396afbbc0d01506e7fae47b018bac2b1d"
-
-[[package]]
-name = "maybe-async"
-version = "0.2.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5cf92c10c7e361d6b99666ec1c6f9805b0bea2c3bd8c78dc6fe98ac5bd78db11"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "mls-rs-codec"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35855223b5af2d2d6f987d418f1b658d518c79a73a95664ec9357dd318f64562"
-dependencies = [
- "mls-rs-codec-derive",
- "thiserror",
- "wasm-bindgen",
-]
-
-[[package]]
-name = "mls-rs-codec-derive"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f3fbf25b68713ec768c250f2b450c93ed997a5d2127b255d547ea7c6b21872b"
-dependencies = [
- "darling",
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "mls-rs-core"
-version = "0.17.1"
-dependencies = [
- "arbitrary",
- "assert_matches",
- "async-trait",
- "hex",
- "itertools",
- "maybe-async",
- "mls-rs-codec",
- "safer-ffi",
- "safer-ffi-gen",
- "serde",
- "serde_json",
- "thiserror",
- "wasm-bindgen",
- "wasm-bindgen-test",
- "zeroize",
-]
-
-[[package]]
-name = "once_cell"
-version = "1.19.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
-dependencies = [
- "critical-section",
- "portable-atomic",
-]
-
-[[package]]
-name = "paste"
-version = "1.0.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
-
-[[package]]
-name = "portable-atomic"
-version = "1.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
-
-[[package]]
-name = "prettyplease"
-version = "0.1.25"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86"
-dependencies = [
- "proc-macro2",
- "syn 1.0.109",
-]
-
-[[package]]
-name = "proc-macro-error"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
-dependencies = [
- "proc-macro-error-attr",
- "proc-macro2",
- "quote",
- "syn 1.0.109",
- "version_check",
-]
-
-[[package]]
-name = "proc-macro-error-attr"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
-dependencies = [
- "proc-macro2",
- "quote",
- "version_check",
-]
-
-[[package]]
-name = "proc-macro2"
-version = "1.0.78"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
-dependencies = [
- "unicode-ident",
-]
-
-[[package]]
-name = "quote"
-version = "1.0.35"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
-dependencies = [
- "proc-macro2",
-]
-
-[[package]]
-name = "ryu"
-version = "1.0.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
-
-[[package]]
-name = "safer-ffi"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4483c5ab47f222d2c297e73a520c9003e09e2fe1f1b04edcb572e6939f303003"
-dependencies = [
- "libc",
- "macro_rules_attribute",
- "paste",
- "safer_ffi-proc_macros",
- "scopeguard",
- "uninit",
- "unwind_safe",
- "with_builtin_macros",
-]
-
-[[package]]
-name = "safer-ffi-gen"
-version = "0.9.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bdc3e72a8e99de537461ab5e9331d32c08dd558493e844cb70753a9890fdbc48"
-dependencies = [
- "once_cell",
- "safer-ffi",
- "safer-ffi-gen-macro",
-]
-
-[[package]]
-name = "safer-ffi-gen-macro"
-version = "0.9.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "836aa8cd7b269dcdd3d81cca1ddc136aa1d2b05f30b6a34c0ff075152b2e3771"
-dependencies = [
- "heck",
- "proc-macro-error",
- "proc-macro2",
- "quote",
- "syn 2.0.50",
- "thiserror",
-]
-
-[[package]]
-name = "safer_ffi-proc_macros"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf04ebd3786110e64269a74eea58c5564dd92a1e790c0f6f9871d6fe1b8e34db"
-dependencies = [
- "macro_rules_attribute",
- "prettyplease",
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
-
-[[package]]
-name = "scoped-tls"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
-
-[[package]]
-name = "scopeguard"
-version = "1.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
-
-[[package]]
-name = "serde"
-version = "1.0.197"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
-dependencies = [
- "serde_derive",
-]
-
-[[package]]
-name = "serde_derive"
-version = "1.0.197"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "serde_json"
-version = "1.0.114"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
-dependencies = [
- "itoa",
- "ryu",
- "serde",
-]
-
-[[package]]
-name = "strsim"
-version = "0.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
-
-[[package]]
-name = "syn"
-version = "1.0.109"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
-
-[[package]]
-name = "syn"
-version = "2.0.50"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
-
-[[package]]
-name = "thiserror"
-version = "1.0.57"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
-dependencies = [
- "thiserror-impl",
-]
-
-[[package]]
-name = "thiserror-impl"
-version = "1.0.57"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "unicode-ident"
-version = "1.0.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
-
-[[package]]
-name = "uninit"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e130f2ed46ca5d8ec13c7ff95836827f92f5f5f37fd2b2bf16f33c408d98bb6"
-dependencies = [
- "extension-traits",
-]
-
-[[package]]
-name = "unwind_safe"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0976c77def3f1f75c4ef892a292c31c0bbe9e3d0702c63044d7c76db298171a3"
-
-[[package]]
-name = "version_check"
-version = "0.9.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
-
-[[package]]
-name = "wasm-bindgen"
-version = "0.2.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
-dependencies = [
- "cfg-if",
- "wasm-bindgen-macro",
-]
-
-[[package]]
-name = "wasm-bindgen-backend"
-version = "0.2.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b"
-dependencies = [
- "bumpalo",
- "log",
- "once_cell",
- "proc-macro2",
- "quote",
- "syn 2.0.50",
- "wasm-bindgen-shared",
-]
-
-[[package]]
-name = "wasm-bindgen-futures"
-version = "0.4.41"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97"
-dependencies = [
- "cfg-if",
- "js-sys",
- "wasm-bindgen",
- "web-sys",
-]
-
-[[package]]
-name = "wasm-bindgen-macro"
-version = "0.2.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed"
-dependencies = [
- "quote",
- "wasm-bindgen-macro-support",
-]
-
-[[package]]
-name = "wasm-bindgen-macro-support"
-version = "0.2.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
- "wasm-bindgen-backend",
- "wasm-bindgen-shared",
-]
-
-[[package]]
-name = "wasm-bindgen-shared"
-version = "0.2.91"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
-
-[[package]]
-name = "wasm-bindgen-test"
-version = "0.3.41"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "143ddeb4f833e2ed0d252e618986e18bfc7b0e52f2d28d77d05b2f045dd8eb61"
-dependencies = [
- "console_error_panic_hook",
- "js-sys",
- "scoped-tls",
- "wasm-bindgen",
- "wasm-bindgen-futures",
- "wasm-bindgen-test-macro",
-]
-
-[[package]]
-name = "wasm-bindgen-test-macro"
-version = "0.3.41"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a5211b7550606857312bba1d978a8ec75692eae187becc5e680444fffc5e6f89"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
-
-[[package]]
-name = "web-sys"
-version = "0.3.68"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446"
-dependencies = [
- "js-sys",
- "wasm-bindgen",
-]
-
-[[package]]
-name = "with_builtin_macros"
-version = "0.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a59d55032495429b87f9d69954c6c8602e4d3f3e0a747a12dea6b0b23de685da"
-dependencies = [
- "with_builtin_macros-proc_macros",
-]
-
-[[package]]
-name = "with_builtin_macros-proc_macros"
-version = "0.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "15bd7679c15e22924f53aee34d4e448c45b674feb6129689af88593e129f8f42"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
-
-[[package]]
-name = "zeroize"
-version = "1.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
-dependencies = [
- "zeroize_derive",
-]
-
-[[package]]
-name = "zeroize_derive"
-version = "1.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
-]
diff --git a/Cargo.toml b/Cargo.toml
index bb46a82..130539a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2021"
name = "mls-rs-core"
-version = "0.17.1"
+version = "0.18.0"
exclude = ["test_data"]
description = "Core components and traits for mls-rs"
homepage = "https://github.com/awslabs/mls-rs"
@@ -30,11 +30,7 @@ optional = true
[dependencies.hex]
version = "^0.4.3"
-features = [
- "serde",
- "alloc",
-]
-optional = true
+features = ["alloc"]
default-features = false
[dependencies.itertools]
@@ -42,10 +38,10 @@ version = "0.12"
optional = true
[dependencies.maybe-async]
-version = "0.2.7"
+version = "0.2.10"
[dependencies.mls-rs-codec]
-version = "0.5.0"
+version = "0.5.2"
default-features = false
[dependencies.safer-ffi]
@@ -67,6 +63,10 @@ features = [
optional = true
default-features = false
+[dependencies.serde_bytes]
+version = "0.11"
+optional = true
+
[dependencies.serde_json]
version = "^1.0"
optional = true
@@ -102,16 +102,22 @@ ffi = [
"dep:safer-ffi-gen",
]
rfc_compliant = ["x509"]
+serde = [
+ "dep:serde",
+ "zeroize/serde",
+ "hex/serde",
+ "dep:serde_bytes",
+]
std = [
"mls-rs-codec/std",
"zeroize/std",
"safer-ffi-gen?/std",
"dep:thiserror",
+ "serde?/std",
]
test_suite = [
- "dep:serde",
+ "serde",
"dep:serde_json",
- "dep:hex",
"dep:itertools",
]
x509 = []
diff --git a/METADATA b/METADATA
index b838d1b..1b60a94 100644
--- a/METADATA
+++ b/METADATA
@@ -1,21 +1,25 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/mls-rs-core
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "mls-rs-core"
description: "Core components and traits for mls-rs"
third_party {
+ license_type: NOTICE
+ last_upgrade_date {
+ year: 2024
+ month: 4
+ day: 26
+ }
identifier {
type: "crates.io"
- value: "mls-rs-core"
+ value: "https://static.crates.io/crates/mls-rs-core/mls-rs-core-0.18.0.crate"
+ version: "0.17.1"
}
identifier {
type: "Archive"
value: "https://static.crates.io/crates/mls-rs-core/mls-rs-core-0.17.1.crate"
+ version: "0.18.0"
primary_source: true
}
- version: "0.17.1"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
- license_type: NOTICE
- last_upgrade_date {
- year: 2024
- month: 3
- day: 22
- }
}
diff --git a/patches/add-license-files.patch b/patches/add-license-files.patch
new file mode 100644
index 0000000..90dedde
--- /dev/null
+++ b/patches/add-license-files.patch
@@ -0,0 +1,204 @@
+Add license files not present in the downloaded crates
+
+The Apache-2.0 and MIT licenses found here are from:
+
+https://github.com/awslabs/mls-rs/blob/main/LICENSE-apache
+https://github.com/awslabs/mls-rs/blob/main/LICENSE-mit
+
+diff --git a/LICENSE-apache b/LICENSE-apache
+new file mode 100644
+index 0000000..831fbc5
+--- /dev/null
++++ b/LICENSE-apache
+@@ -0,0 +1,176 @@
++ Apache License
++ Version 2.0, January 2004
++ http://www.apache.org/licenses/
++
++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
++
++ 1. Definitions.
++
++ "License" shall mean the terms and conditions for use, reproduction,
++ and distribution as defined by Sections 1 through 9 of this document.
++
++ "Licensor" shall mean the copyright owner or entity authorized by
++ the copyright owner that is granting the License.
++
++ "Legal Entity" shall mean the union of the acting entity and all
++ other entities that control, are controlled by, or are under common
++ control with that entity. For the purposes of this definition,
++ "control" means (i) the power, direct or indirect, to cause the
++ direction or management of such entity, whether by contract or
++ otherwise, or (ii) ownership of fifty percent (50%) or more of the
++ outstanding shares, or (iii) beneficial ownership of such entity.
++
++ "You" (or "Your") shall mean an individual or Legal Entity
++ exercising permissions granted by this License.
++
++ "Source" form shall mean the preferred form for making modifications,
++ including but not limited to software source code, documentation
++ source, and configuration files.
++
++ "Object" form shall mean any form resulting from mechanical
++ transformation or translation of a Source form, including but
++ not limited to compiled object code, generated documentation,
++ and conversions to other media types.
++
++ "Work" shall mean the work of authorship, whether in Source or
++ Object form, made available under the License, as indicated by a
++ copyright notice that is included in or attached to the work
++ (an example is provided in the Appendix below).
++
++ "Derivative Works" shall mean any work, whether in Source or Object
++ form, that is based on (or derived from) the Work and for which the
++ editorial revisions, annotations, elaborations, orother modifications
++ represent, as a whole, an original work of authorship. For the purposes
++ of this License, Derivative Works shall not include works that remain
++ separable from, or merely link (or bind by name) to the interfaces of,
++ the Work and Derivative Works thereof.
++
++ "Contribution" shall mean any work of authorship, including
++ the original version of the Work and any modifications or additions
++ to that Work or Derivative Works thereof, that is intentionally
++ submitted to Licensor for inclusion in the Work by the copyright owner
++ or by an individual or Legal Entity authorized to submit on behalf of
++ the copyright owner. For the purposes of this definition, "submitted"
++ means any form of electronic, verbal, or written communication sent
++ to the Licensor or its representatives, including but not limited to
++ communication on electronic mailing lists, source code control systems,
++ and issue tracking systems that are managed by, or on behalf of, the
++ Licensor for the purpose of discussing and improving the Work, but
++ excluding communication that is conspicuously marked or otherwise
++ designated in writing by the copyright owner as "Not a Contribution."
++
++ "Contributor" shall mean Licensor and any individual or Legal Entity
++ on behalf of whom a Contribution has been received by Licensor and
++ subsequently incorporated within the Work.
++
++ 2. Grant of Copyright License. Subject to the terms and conditions of
++ this License, each Contributor hereby grants to You a perpetual,
++ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
++ copyright license to reproduce, prepare Derivative Works of,
++ publicly display, publicly perform, sublicense, and distribute the
++ Work and such Derivative Works in Source or Object form.
++
++ 3. Grant of Patent License. Subject to the terms and conditions of
++ this License, each Contributor hereby grants to You a perpetual,
++ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
++ (except as stated in this section) patent license to make, have made,
++ use, offer to sell, sell, import, and otherwise transfer the Work,
++ where such license applies only to those patent claims licensable
++ by such Contributor that are necessarily infringed by their
++ Contribution(s) alone or by combination of their Contribution(s)
++ with the Work to which such Contribution(s) was submitted. If You
++ institute patent litigation against any entity (including a
++ cross-claim or counterclaim in a lawsuit) alleging that the Work
++ or a Contribution incorporated within the Work constitutes direct
++ or contributory patent infringement, then any patent licenses
++ granted to You under this License for that Work shall terminate
++ as of the date such litigation is filed.
++
++ 4. Redistribution. You may reproduce and distribute copies of the
++ Work or Derivative Works thereof in any medium, with or without
++ modifications, and in Source or Object form, provided that You
++ meet the following conditions:
++
++ (a) You must give any other recipients of the Work or
++ Derivative Works a copy of this License; and
++
++ (b) You must cause any modified files to carry prominent notices
++ stating that You changed the files; and
++
++ (c) You must retain, in the Source form of any Derivative Works
++ that You distribute, all copyright, patent, trademark, and
++ attribution notices from the Source form of the Work,
++ excluding those notices that do not pertain to any part of
++ the Derivative Works; and
++
++ (d) If the Work includes a "NOTICE" text file as part of its
++ distribution, then any Derivative Works that You distribute must
++ include a readable copy of the attribution notices contained
++ within such NOTICE file, excluding those notices that do not
++ pertain to any part of the Derivative Works, in at least one
++ of the following places: within a NOTICE text file distributed
++ as part of the Derivative Works; within the Source form or
++ documentation, if provided along with the Derivative Works; or,
++ within a display generated by the Derivative Works, if and
++ wherever such third-party notices normally appear. The contents
++ of the NOTICE file are for informational purposes only and
++ do not modify the License. You may add Your own attribution
++ notices within Derivative Works that You distribute, alongside
++ or as an addendum to the NOTICE text from the Work, provided
++ that such additional attribution notices cannot be construed
++ as modifying the License.
++
++ You may add Your own copyright statement to Your modifications and
++ may provide additional or different license terms and conditions
++ for use, reproduction, or distribution of Your modifications, or
++ for any such Derivative Works as a whole, provided Your use,
++ reproduction, and distribution of the Work otherwise complies with
++ the conditions stated in this License.
++
++ 5. Submission of Contributions. Unless You explicitly state otherwise,
++ any Contribution intentionally submitted for inclusion in the Work
++ by You to the Licensor shall be under the terms and conditions of
++ this License, without any additional terms or conditions.
++ Notwithstanding the above, nothing herein shall supersede or modify
++ the terms of any separate license agreement you may have executed
++ with Licensor regarding such Contributions.
++
++ 6. Trademarks. This License does not grant permission to use the trade
++ names, trademarks, service marks, or product names of the Licensor,
++ except as required for reasonable and customary use in describing the
++ origin of the Work and reproducing the content of the NOTICE file.
++
++ 7. Disclaimer of Warranty. Unless required by applicable law or
++ agreed to in writing, Licensor provides the Work (and each
++ Contributor provides its Contributions) on an "AS IS" BASIS,
++ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
++ implied, including, without limitation, any warranties or conditions
++ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
++ PARTICULAR PURPOSE. You are solely responsible for determining the
++ appropriateness of using or redistributing the Work and assume any
++ risks associated with Your exercise of permissions under this License.
++
++ 8. Limitation of Liability. In no event and under no legal theory,
++ whether in tort (including negligence), contract, or otherwise,
++ unless required by applicable law (such as deliberate and grossly
++ negligent acts) or agreed to in writing, shall any Contributor be
++ liable to You for damages, including any direct, indirect, special,
++ incidental, or consequential damages of any character arising as a
++ result of this License or out of the use or inability to use the
++ Work (including but not limited to damages for loss of goodwill,
++ work stoppage, computer failure or malfunction, or any and all
++ other commercial damages or losses), even if such Contributor
++ has been advised of the possibility of such damages.
++
++ 9. Accepting Warranty or Additional Liability. While redistributing
++ the Work or Derivative Works thereof, You may choose to offer,
++ and charge a fee for, acceptance of support, warranty, indemnity,
++ or other liability obligations and/or rights consistent with this
++ License. However, in accepting such obligations, You may act only
++ on Your own behalf and on Your sole responsibility, not on behalf
++ of any other Contributor, and only if You agree to indemnify,
++ defend, and hold each Contributor harmless for any liability
++ incurred by, or claims asserted against, such Contributor by reason
++ of your accepting any such warranty or additional liability.
++
++ END OF TERMS AND CONDITIONS
+diff --git a/LICENSE-mit b/LICENSE-mit
+new file mode 100644
+index 0000000..e547c4a
+--- /dev/null
++++ b/LICENSE-mit
+@@ -0,0 +1,9 @@
++MIT License
++
++Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
++
++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
++
++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
++
++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/crypto.rs b/src/crypto.rs
index 4594eeb..30301bb 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -5,7 +5,10 @@
use crate::error::IntoAnyError;
use alloc::vec;
use alloc::vec::Vec;
-use core::ops::Deref;
+use core::{
+ fmt::{self, Debug},
+ ops::Deref,
+};
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use zeroize::{ZeroizeOnDrop, Zeroizing};
@@ -15,25 +18,50 @@ pub use self::cipher_suite::*;
#[cfg(feature = "test_suite")]
pub mod test_suite;
-#[derive(Clone, Debug, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Ciphertext produced by [`CipherSuiteProvider::hpke_seal`]
pub struct HpkeCiphertext {
#[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub kem_output: Vec<u8>,
#[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub ciphertext: Vec<u8>,
}
+impl Debug for HpkeCiphertext {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("HpkeCiphertext")
+ .field("kem_output", &crate::debug::pretty_bytes(&self.kem_output))
+ .field("ciphertext", &crate::debug::pretty_bytes(&self.ciphertext))
+ .finish()
+ }
+}
+
/// Byte representation of an HPKE public key. For ciphersuites using elliptic curves,
/// the public key should be represented in the uncompressed format.
-#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsDecode, MlsEncode)]
+#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsDecode, MlsEncode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
-pub struct HpkePublicKey(#[mls_codec(with = "mls_rs_codec::byte_vec")] Vec<u8>);
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct HpkePublicKey(
+ #[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
+ Vec<u8>,
+);
+
+impl Debug for HpkePublicKey {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0)
+ .named("HpkePublicKey")
+ .fmt(f)
+ }
+}
impl From<Vec<u8>> for HpkePublicKey {
fn from(data: Vec<u8>) -> Self {
@@ -62,13 +90,26 @@ impl AsRef<[u8]> for HpkePublicKey {
}
/// Byte representation of an HPKE secret key.
-#[derive(Clone, Debug, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode, ZeroizeOnDrop)]
+#[derive(Clone, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode, ZeroizeOnDrop)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
-pub struct HpkeSecretKey(#[mls_codec(with = "mls_rs_codec::byte_vec")] Vec<u8>);
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct HpkeSecretKey(
+ #[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
+ Vec<u8>,
+);
+
+impl Debug for HpkeSecretKey {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0)
+ .named("HpkeSecretKey")
+ .fmt(f)
+ }
+}
impl From<Vec<u8>> for HpkeSecretKey {
fn from(data: Vec<u8>) -> Self {
@@ -135,10 +176,23 @@ pub trait HpkeContextR {
/// Byte representation of a signature public key. For ciphersuites using elliptic curves,
/// the public key should be represented in the uncompressed format.
-#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, Hash, Ord, PartialOrd, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::ffi_type(opaque))]
-pub struct SignaturePublicKey(#[mls_codec(with = "mls_rs_codec::byte_vec")] Vec<u8>);
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct SignaturePublicKey(
+ #[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
+ Vec<u8>,
+);
+
+impl Debug for SignaturePublicKey {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0)
+ .named("SignaturePublicKey")
+ .fmt(f)
+ }
+}
#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::safer_ffi_gen)]
impl SignaturePublicKey {
@@ -180,12 +234,22 @@ impl From<Vec<u8>> for SignaturePublicKey {
all(feature = "ffi", not(test)),
::safer_ffi_gen::ffi_type(clone, opaque)
)]
-#[derive(Clone, Debug, PartialEq, Eq, ZeroizeOnDrop, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, ZeroizeOnDrop, MlsSize, MlsEncode, MlsDecode)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignatureSecretKey {
#[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
bytes: Vec<u8>,
}
+impl Debug for SignatureSecretKey {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.bytes)
+ .named("SignatureSecretKey")
+ .fmt(f)
+ }
+}
+
#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::safer_ffi_gen)]
impl SignatureSecretKey {
pub fn new(bytes: Vec<u8>) -> Self {
diff --git a/src/crypto/cipher_suite.rs b/src/crypto/cipher_suite.rs
index e87e10b..679ac16 100644
--- a/src/crypto/cipher_suite.rs
+++ b/src/crypto/cipher_suite.rs
@@ -27,6 +27,7 @@ use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
#[derive(Debug, Copy, Clone, Eq, PartialEq, MlsSize, MlsEncode, MlsDecode, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct CipherSuite(u16);
diff --git a/src/debug.rs b/src/debug.rs
new file mode 100644
index 0000000..3fe01a7
--- /dev/null
+++ b/src/debug.rs
@@ -0,0 +1,130 @@
+// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// Copyright by contributors to this project.
+// SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+use core::fmt::{self, Debug};
+
+const DEFAULT_BYTES_TYPE_NAME: &str = "Bytes";
+
+pub fn pretty_bytes(bytes: &[u8]) -> PrettyBytes<'_> {
+ PrettyBytes {
+ ty: None,
+ bytes,
+ show_len: true,
+ show_raw: false,
+ }
+}
+
+pub struct PrettyBytes<'a> {
+ ty: Option<&'a str>,
+ bytes: &'a [u8],
+ show_len: bool,
+ show_raw: bool,
+}
+
+impl<'a> PrettyBytes<'a> {
+ pub fn named(self, ty: &'a str) -> Self {
+ Self {
+ ty: Some(ty),
+ ..self
+ }
+ }
+
+ pub fn show_len(self, show: bool) -> Self {
+ Self {
+ show_len: show,
+ ..self
+ }
+ }
+
+ pub fn show_raw(self, show: bool) -> Self {
+ Self {
+ show_raw: show,
+ ..self
+ }
+ }
+}
+
+impl Debug for PrettyBytes<'_> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let show_raw = self.show_raw || f.alternate();
+ match (self.ty, self.show_len, show_raw) {
+ (_, false, false) => show_only_type(self.ty, f),
+ (None, false, true) => show_only_raw(self.bytes, f),
+ (Some(ty), false, true) => show_newtype(ty, self.bytes, f),
+ (_, true, _) => show_struct(self.ty, self.bytes, show_raw, f),
+ }
+ }
+}
+
+fn show_only_type(ty: Option<&str>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(ty.unwrap_or(DEFAULT_BYTES_TYPE_NAME))
+}
+
+fn show_only_raw(bytes: &[u8], f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(&hex::encode(bytes))
+}
+
+fn show_newtype(ty: &str, bytes: &[u8], f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{ty}({})", hex::encode(bytes))
+}
+
+fn show_struct(
+ ty: Option<&str>,
+ bytes: &[u8],
+ show_raw: bool,
+ f: &mut fmt::Formatter<'_>,
+) -> fmt::Result {
+ let ty = ty.unwrap_or(DEFAULT_BYTES_TYPE_NAME);
+ let mut out = f.debug_struct(ty);
+ out.field("len", &bytes.len());
+ if show_raw {
+ out.field("raw", &hex::encode(bytes));
+ }
+ out.finish()
+}
+
+pub fn pretty_with<F>(f: F) -> impl Debug
+where
+ F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
+{
+ PrettyWith(f)
+}
+
+struct PrettyWith<F>(F);
+
+impl<F> Debug for PrettyWith<F>
+where
+ F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
+{
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ self.0(f)
+ }
+}
+
+pub fn pretty_group_id(id: &[u8]) -> impl Debug + '_ {
+ pretty_bytes(id).show_len(false).show_raw(true)
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::debug::pretty_bytes;
+
+ #[test]
+ fn default_format_contains_only_length() {
+ let bytes = pretty_bytes(b"foobar");
+ let output = format!("{bytes:?}");
+ assert!(output.contains("len"));
+ assert!(!output.contains("raw"));
+ assert!(!output.contains(&hex::encode(b"foobar")));
+ }
+
+ #[test]
+ fn alternate_format_contains_length_and_hex_encoded_bytes() {
+ let bytes = pretty_bytes(b"foobar");
+ let output = format!("{bytes:#?}");
+ assert!(output.contains("len"));
+ assert!(output.contains("raw"));
+ assert!(output.contains(&hex::encode(b"foobar")));
+ }
+}
diff --git a/src/extension.rs b/src/extension.rs
index 1f5b6b8..77f8721 100644
--- a/src/extension.rs
+++ b/src/extension.rs
@@ -2,7 +2,10 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
-use core::ops::Deref;
+use core::{
+ fmt::{self, Debug},
+ ops::Deref,
+};
use crate::error::{AnyError, IntoAnyError};
use alloc::vec::Vec;
@@ -19,6 +22,7 @@ pub use list::*;
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct ExtensionType(u16);
@@ -89,12 +93,13 @@ impl IntoAnyError for ExtensionError {
}
}
-#[derive(Clone, Debug, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
/// An MLS protocol [extension](https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol.html#name-extensions).
///
@@ -105,9 +110,22 @@ pub struct Extension {
pub extension_type: ExtensionType,
/// Data held within this extension
#[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub extension_data: Vec<u8>,
}
+impl Debug for Extension {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Extension")
+ .field("extension_type", &self.extension_type)
+ .field(
+ "extension_data",
+ &crate::debug::pretty_bytes(&self.extension_data),
+ )
+ .finish()
+ }
+}
+
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl Extension {
/// Create an extension with specified type and data properties.
diff --git a/src/extension/list.rs b/src/extension/list.rs
index 116c3f9..92df039 100644
--- a/src/extension/list.rs
+++ b/src/extension/list.rs
@@ -19,6 +19,7 @@ use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
safer_ffi_gen::ffi_type(clone, opaque)
)]
#[derive(Debug, Clone, Default, MlsSize, MlsEncode, Eq)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExtensionList(Vec<Extension>);
impl Deref for ExtensionList {
diff --git a/src/group/group_state.rs b/src/group/group_state.rs
index 42ece05..659901c 100644
--- a/src/group/group_state.rs
+++ b/src/group/group_state.rs
@@ -2,22 +2,51 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
+use core::fmt::{self, Debug};
+
use crate::error::IntoAnyError;
#[cfg(mls_build_async)]
use alloc::boxed::Box;
use alloc::vec::Vec;
-use mls_rs_codec::{MlsDecode, MlsEncode};
/// Generic representation of a group's state.
-pub trait GroupState {
+#[derive(Clone, PartialEq, Eq)]
+pub struct GroupState {
/// A unique group identifier.
- fn id(&self) -> Vec<u8>;
+ pub id: Vec<u8>,
+ pub data: Vec<u8>,
+}
+
+impl Debug for GroupState {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("GroupState")
+ .field("id", &crate::debug::pretty_bytes(&self.id))
+ .field("data", &crate::debug::pretty_bytes(&self.data))
+ .finish()
+ }
}
/// Generic representation of a prior epoch.
-pub trait EpochRecord {
+#[derive(Clone, PartialEq, Eq)]
+pub struct EpochRecord {
/// A unique epoch identifier within a particular group.
- fn id(&self) -> u64;
+ pub id: u64,
+ pub data: Vec<u8>,
+}
+
+impl Debug for EpochRecord {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("EpochRecord")
+ .field("id", &self.id)
+ .field("data", &crate::debug::pretty_bytes(&self.data))
+ .finish()
+ }
+}
+
+impl EpochRecord {
+ pub fn new(id: u64, data: Vec<u8>) -> Self {
+ Self { id, data }
+ }
}
/// Storage that can persist and reload a group state.
@@ -41,14 +70,10 @@ pub trait GroupStateStorage: Send + Sync {
type Error: IntoAnyError;
/// Fetch a group state from storage.
- async fn state<T>(&self, group_id: &[u8]) -> Result<Option<T>, Self::Error>
- where
- T: GroupState + MlsEncode + MlsDecode;
+ async fn state(&self, group_id: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>;
/// Lazy load cached epoch data from a particular group.
- async fn epoch<T>(&self, group_id: &[u8], epoch_id: u64) -> Result<Option<T>, Self::Error>
- where
- T: EpochRecord + MlsEncode + MlsDecode;
+ async fn epoch(&self, group_id: &[u8], epoch_id: u64) -> Result<Option<Vec<u8>>, Self::Error>;
/// Write pending state updates.
///
@@ -69,15 +94,12 @@ pub trait GroupStateStorage: Send + Sync {
/// of this trait. Calls to [`write`](GroupStateStorage::write) should
/// optimally be a single atomic transaction in order to avoid partial writes
/// that may corrupt the group state.
- async fn write<ST, ET>(
+ async fn write(
&mut self,
- state: ST,
- epoch_inserts: Vec<ET>,
- epoch_updates: Vec<ET>,
- ) -> Result<(), Self::Error>
- where
- ST: GroupState + MlsEncode + MlsDecode + Send + Sync,
- ET: EpochRecord + MlsEncode + MlsDecode + Send + Sync;
+ state: GroupState,
+ epoch_inserts: Vec<EpochRecord>,
+ epoch_updates: Vec<EpochRecord>,
+ ) -> Result<(), Self::Error>;
/// The [`EpochRecord::id`] value that is associated with a stored
/// prior epoch for a particular group.
diff --git a/src/group/proposal_type.rs b/src/group/proposal_type.rs
index b1e6e75..976cfae 100644
--- a/src/group/proposal_type.rs
+++ b/src/group/proposal_type.rs
@@ -14,6 +14,7 @@ use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct ProposalType(u16);
diff --git a/src/group/roster.rs b/src/group/roster.rs
index 9c93937..b657edf 100644
--- a/src/group/roster.rs
+++ b/src/group/roster.rs
@@ -21,6 +21,7 @@ use super::ProposalType;
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Capabilities of a MLS client
pub struct Capabilities {
pub protocol_versions: Vec<ProtocolVersion>,
diff --git a/src/identity/basic.rs b/src/identity/basic.rs
index a5a52c9..39eb816 100644
--- a/src/identity/basic.rs
+++ b/src/identity/basic.rs
@@ -2,19 +2,23 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
-use core::convert::Infallible;
+use core::{
+ convert::Infallible,
+ fmt::{self, Debug},
+};
use alloc::vec::Vec;
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use super::{Credential, CredentialType, MlsCredential};
-#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Bare assertion of an identity without any additional information.
///
/// The format of the encoded identity is defined by the application.
@@ -28,9 +32,18 @@ use super::{Credential, CredentialType, MlsCredential};
pub struct BasicCredential {
/// Underlying identifier as raw bytes.
#[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub identifier: Vec<u8>,
}
+impl Debug for BasicCredential {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.identifier)
+ .named("BasicCredential")
+ .fmt(f)
+ }
+}
+
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl BasicCredential {
/// Create a new basic credential with raw bytes.
diff --git a/src/identity/credential.rs b/src/identity/credential.rs
index c1eaf1c..73c2861 100644
--- a/src/identity/credential.rs
+++ b/src/identity/credential.rs
@@ -2,7 +2,10 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
-use core::ops::Deref;
+use core::{
+ fmt::{self, Debug},
+ ops::Deref,
+};
use alloc::vec::Vec;
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
@@ -19,6 +22,7 @@ use super::CertificateChain;
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct CredentialType(u16);
@@ -54,12 +58,13 @@ impl Deref for CredentialType {
}
}
-#[derive(Clone, Debug, MlsSize, MlsEncode, MlsDecode, PartialEq, Eq, Hash, PartialOrd, Ord)]
+#[derive(Clone, MlsSize, MlsEncode, MlsDecode, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Custom user created credential type.
///
/// # Warning
@@ -72,9 +77,19 @@ pub struct CustomCredential {
pub credential_type: CredentialType,
/// Opaque data representing this custom credential.
#[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub data: Vec<u8>,
}
+impl Debug for CustomCredential {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("CustomCredential")
+ .field("credential_type", &self.credential_type)
+ .field("data", &crate::debug::pretty_bytes(&self.data))
+ .finish()
+ }
+}
+
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl CustomCredential {
/// Create a new custom credential with opaque data.
@@ -110,6 +125,7 @@ impl CustomCredential {
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Credential {
/// Basic identifier-only credential.
diff --git a/src/identity/signing_identity.rs b/src/identity/signing_identity.rs
index 870e58f..b8bfd9d 100644
--- a/src/identity/signing_identity.rs
+++ b/src/identity/signing_identity.rs
@@ -14,6 +14,7 @@ use super::Credential;
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// MLS group member identity represented as a combination of a
/// public [`SignaturePublicKey`] and [`Credential`].
pub struct SigningIdentity {
diff --git a/src/identity/x509.rs b/src/identity/x509.rs
index 2f7d96c..e3ac8ea 100644
--- a/src/identity/x509.rs
+++ b/src/identity/x509.rs
@@ -4,6 +4,7 @@
use core::{
convert::Infallible,
+ fmt::{self, Debug},
ops::{Deref, DerefMut},
};
@@ -12,14 +13,27 @@ use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use super::{Credential, CredentialType, MlsCredential};
-#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// X.509 certificate in DER format.
-pub struct DerCertificate(#[mls_codec(with = "mls_rs_codec::byte_vec")] Vec<u8>);
+pub struct DerCertificate(
+ #[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
+ Vec<u8>,
+);
+
+impl Debug for DerCertificate {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0)
+ .named("DerCertificate")
+ .fmt(f)
+ }
+}
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl DerCertificate {
@@ -60,6 +74,7 @@ impl AsRef<[u8]> for DerCertificate {
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// A chain of [`DerCertificate`] that is ordered from leaf to root.
///
/// Certificate chains MAY leave out root CA's so long as they are
diff --git a/src/key_package.rs b/src/key_package.rs
index d2dedaa..84c7cfa 100644
--- a/src/key_package.rs
+++ b/src/key_package.rs
@@ -5,20 +5,37 @@
#[cfg(mls_build_async)]
use alloc::boxed::Box;
use alloc::vec::Vec;
+use core::fmt::{self, Debug};
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use crate::{crypto::HpkeSecretKey, error::IntoAnyError};
-#[derive(Debug, Clone, PartialEq, Eq, MlsEncode, MlsDecode, MlsSize)]
+#[derive(Clone, PartialEq, Eq, MlsEncode, MlsDecode, MlsSize)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
/// Representation of a generated key package and secret keys.
pub struct KeyPackageData {
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
pub key_package_bytes: Vec<u8>,
pub init_key: HpkeSecretKey,
pub leaf_node_key: HpkeSecretKey,
pub expiration: u64,
}
+impl Debug for KeyPackageData {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("KeyPackageData")
+ .field(
+ "key_package_bytes",
+ &crate::debug::pretty_bytes(&self.key_package_bytes),
+ )
+ .field("init_key", &self.init_key)
+ .field("leaf_node_key", &self.leaf_node_key)
+ .field("expiration", &self.expiration)
+ .finish()
+ }
+}
+
impl KeyPackageData {
pub fn new(
key_package_bytes: Vec<u8>,
diff --git a/src/lib.rs b/src/lib.rs
index 8dc6088..c7ee802 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,6 +10,7 @@ extern crate alloc;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
pub mod crypto;
+pub mod debug;
pub mod error;
pub mod extension;
pub mod group;
@@ -24,3 +25,42 @@ pub use mls_rs_codec;
#[cfg(feature = "arbitrary")]
pub use arbitrary;
+
+#[cfg(feature = "serde")]
+pub mod zeroizing_serde {
+ use alloc::vec::Vec;
+ use serde::{Deserializer, Serializer};
+ use zeroize::Zeroizing;
+
+ use crate::vec_serde;
+
+ pub fn serialize<S: Serializer>(v: &Zeroizing<Vec<u8>>, s: S) -> Result<S::Ok, S::Error> {
+ vec_serde::serialize(v, s)
+ }
+
+ pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Zeroizing<Vec<u8>>, D::Error> {
+ vec_serde::deserialize(d).map(Zeroizing::new)
+ }
+}
+
+#[cfg(feature = "serde")]
+pub mod vec_serde {
+ use alloc::vec::Vec;
+ use serde::{Deserializer, Serializer};
+
+ pub fn serialize<S: Serializer>(v: &Vec<u8>, s: S) -> Result<S::Ok, S::Error> {
+ if s.is_human_readable() {
+ hex::serde::serialize(v, s)
+ } else {
+ serde_bytes::serialize(v, s)
+ }
+ }
+
+ pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<u8>, D::Error> {
+ if d.is_human_readable() {
+ hex::serde::deserialize(d)
+ } else {
+ serde_bytes::deserialize(d)
+ }
+ }
+}
diff --git a/src/protocol_version.rs b/src/protocol_version.rs
index 4c9e5ee..05bcced 100644
--- a/src/protocol_version.rs
+++ b/src/protocol_version.rs
@@ -12,6 +12,7 @@ use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct ProtocolVersion(u16);
diff --git a/src/psk.rs b/src/psk.rs
index 4b26442..99529bd 100644
--- a/src/psk.rs
+++ b/src/psk.rs
@@ -6,13 +6,29 @@ use crate::error::IntoAnyError;
#[cfg(mls_build_async)]
use alloc::boxed::Box;
use alloc::vec::Vec;
-use core::ops::Deref;
+use core::{
+ fmt::{self, Debug},
+ ops::Deref,
+};
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use zeroize::Zeroizing;
-#[derive(Clone, Debug, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, PartialEq, Eq, MlsSize, MlsEncode, MlsDecode)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Wrapper type that holds a pre-shared key value and zeroizes on drop.
-pub struct PreSharedKey(#[mls_codec(with = "mls_rs_codec::byte_vec")] Zeroizing<Vec<u8>>);
+pub struct PreSharedKey(
+ #[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::zeroizing_serde"))]
+ Zeroizing<Vec<u8>>,
+);
+
+impl Debug for PreSharedKey {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0)
+ .named("PreSharedKey")
+ .fmt(f)
+ }
+}
impl PreSharedKey {
/// Create a new PreSharedKey.
@@ -52,14 +68,27 @@ impl Deref for PreSharedKey {
}
}
-#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq, MlsSize, MlsEncode, MlsDecode)]
+#[derive(Clone, Eq, Hash, Ord, PartialOrd, PartialEq, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// An external pre-shared key identifier.
-pub struct ExternalPskId(#[mls_codec(with = "mls_rs_codec::byte_vec")] Vec<u8>);
+pub struct ExternalPskId(
+ #[mls_codec(with = "mls_rs_codec::byte_vec")]
+ #[cfg_attr(feature = "serde", serde(with = "crate::vec_serde"))]
+ Vec<u8>,
+);
+
+impl Debug for ExternalPskId {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0)
+ .named("ExternalPskId")
+ .fmt(f)
+ }
+}
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl ExternalPskId {
diff --git a/src/secret.rs b/src/secret.rs
index 524e3bb..f84801c 100644
--- a/src/secret.rs
+++ b/src/secret.rs
@@ -3,17 +3,26 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
use alloc::vec::Vec;
-use core::ops::{Deref, DerefMut};
+use core::{
+ fmt::{self, Debug},
+ ops::{Deref, DerefMut},
+};
use zeroize::Zeroizing;
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
-#[derive(Clone, Debug, Eq, PartialEq)]
+#[derive(Clone, Eq, PartialEq)]
/// Wrapper struct that represents a zeroize-on-drop `Vec<u8>`
pub struct Secret(Zeroizing<Vec<u8>>);
+impl Debug for Secret {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ crate::debug::pretty_bytes(&self.0).named("Secret").fmt(f)
+ }
+}
+
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)]
impl Secret {
pub fn as_bytes(&self) -> &[u8] {
diff --git a/src/time.rs b/src/time.rs
index 9c104f7..57f7a28 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -9,6 +9,7 @@ use wasm_bindgen::prelude::*;
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct MlsTime {
seconds: u64,