diff --git a/Cargo.toml b/Cargo.toml index f29ad56..96f124e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ eyre = "0.6" serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] -criterion = "0.5" +criterion = { version = "0.5", default_features = false } pretty_assertions = "1.3" proteus-wasm = { path = ".", package = "proteus-wasm", features = ["hazmat", "cryptobox-identity", "public-key-batch-verification"] } wasm-bindgen-test = "0.3" diff --git a/crates/cbor-codec/Cargo.toml b/crates/cbor-codec/Cargo.toml index dd654c4..beb5835 100644 --- a/crates/cbor-codec/Cargo.toml +++ b/crates/cbor-codec/Cargo.toml @@ -13,12 +13,10 @@ edition = "2021" [lib] name = "cbor" -[features] -random = ["quickcheck"] - [dependencies] byteorder = "1.4" half = "2.1" +rand = "0.8" [dependencies.quickcheck] version = "1.0" diff --git a/crates/cbor-codec/src/decoder.rs b/crates/cbor-codec/src/decoder.rs index c4c5f75..96730b7 100644 --- a/crates/cbor-codec/src/decoder.rs +++ b/crates/cbor-codec/src/decoder.rs @@ -15,10 +15,10 @@ //! The module is structured as follows: //! //! 1. `Kernel` contains the basic decoding functionality, capable of -//! decoding simple unstructured types. +//! decoding simple unstructured types. //! 2. `Decoder` directly decodes into native Rust types. //! 3. `GenericDecoder` handles arbitrary CBOR items and decodes them -//! into an `Value` AST. +//! into an `Value` AST. //! //! # Example 1: Direct decoding //! @@ -36,19 +36,17 @@ //! use cbor::{Config, Decoder}; //! use std::io::Cursor; //! -//! fn main() { -//! let input = Cursor::new(hex::decode("828301020383010203").unwrap()); -//! let mut dec = Decoder::new(Config::default(), input); -//! let mut res = Vec::new(); +//! let input = Cursor::new(hex::decode("828301020383010203").unwrap()); +//! let mut dec = Decoder::new(Config::default(), input); +//! let mut res = Vec::new(); +//! for _ in 0 .. dec.array().unwrap() { +//! let mut vec = Vec::new(); //! for _ in 0 .. dec.array().unwrap() { -//! let mut vec = Vec::new(); -//! for _ in 0 .. dec.array().unwrap() { -//! vec.push(dec.u8().unwrap()) -//! } -//! res.push(vec) +//! vec.push(dec.u8().unwrap()) //! } -//! assert_eq!(vec![vec![1, 2, 3], vec![1, 2, 3]], res) +//! res.push(vec) //! } +//! assert_eq!(vec![vec![1, 2, 3], vec![1, 2, 3]], res) //! ``` //! //! # Example 3: Generic decoding @@ -58,14 +56,12 @@ //! use cbor::value::{self, Key}; //! use std::io::Cursor; //! -//! fn main() { -//! let input = Cursor::new(hex::decode("a2616101028103").unwrap()); -//! let mut d = GenericDecoder::new(Config::default(), input); -//! let value = d.value().unwrap(); -//! let c = value::Cursor::new(&value); -//! assert_eq!(Some(1), c.field("a").u8()); -//! assert_eq!(Some(3), c.get(Key::u64(2)).at(0).u8()) -//! } +//! let input = Cursor::new(hex::decode("a2616101028103").unwrap()); +//! let mut d = GenericDecoder::new(Config::default(), input); +//! let value = d.value().unwrap(); +//! let c = value::Cursor::new(&value); +//! assert_eq!(Some(1), c.field("a").u8()); +//! assert_eq!(Some(3), c.get(Key::u64(2)).at(0).u8()) //! ``` //! //! # Example 4: Direct decoding (optional value) @@ -90,7 +86,6 @@ use std::fmt; use std::io; use std::str::{from_utf8, Utf8Error}; use std::string; -use std::{i16, i32, i64, i8}; // Decoder Configuration //////////////////////////////////////////////////// @@ -1349,7 +1344,6 @@ mod tests { use crate::value::{self, Int, Key, Simple, Value}; use std::collections::BTreeMap; use std::io::Cursor; - use std::{f32, f64, u64}; #[test] fn unsigned() { diff --git a/crates/cbor-codec/src/encoder.rs b/crates/cbor-codec/src/encoder.rs index 4546c22..8341d46 100644 --- a/crates/cbor-codec/src/encoder.rs +++ b/crates/cbor-codec/src/encoder.rs @@ -15,11 +15,9 @@ //! use cbor::Encoder; //! use std::io::Cursor; //! -//! fn main() { -//! let mut e = Encoder::new(Cursor::new(Vec::new())); -//! e.u16(1000).unwrap(); -//! assert_eq!(hex::decode("1903e8").unwrap(), e.into_writer().into_inner()) -//! } +//! let mut e = Encoder::new(Cursor::new(Vec::new())); +//! e.u16(1000).unwrap(); +//! assert_eq!(hex::decode("1903e8").unwrap(), e.into_writer().into_inner()) //! ``` //! //! # Example 2: Direct encoding (indefinite string) @@ -28,12 +26,10 @@ //! use cbor::Encoder; //! use std::io::Cursor; //! -//! fn main() { -//! let mut e = Encoder::new(Cursor::new(Vec::new())); -//! e.text_iter(vec!["strea", "ming"].into_iter()).unwrap(); -//! let output = hex::decode("7f657374726561646d696e67ff").unwrap(); -//! assert_eq!(output, e.into_writer().into_inner()) -//! } +//! let mut e = Encoder::new(Cursor::new(Vec::new())); +//! e.text_iter(vec!["strea", "ming"].into_iter()).unwrap(); +//! let output = hex::decode("7f657374726561646d696e67ff").unwrap(); +//! assert_eq!(output, e.into_writer().into_inner()) //! ``` //! //! # Example 3: Direct encoding (nested array) @@ -43,16 +39,14 @@ //! use cbor::Encoder; //! use std::io::Cursor; //! -//! fn main() { -//! let mut e = Encoder::new(Cursor::new(Vec::new())); -//! e.array(3) -//! .and(e.u8(1)) -//! .and(e.array(2)).and(e.u8(2)).and(e.u8(3)) -//! .and(e.array(2)).and(e.u8(4)).and(e.u8(5)) -//! .unwrap(); -//! let output = hex::decode("8301820203820405").unwrap(); -//! assert_eq!(output, e.into_writer().into_inner()) -//! } +//! let mut e = Encoder::new(Cursor::new(Vec::new())); +//! e.array(3) +//! .and(e.u8(1)) +//! .and(e.array(2)).and(e.u8(2)).and(e.u8(3)) +//! .and(e.array(2)).and(e.u8(4)).and(e.u8(5)) +//! .unwrap(); +//! let output = hex::decode("8301820203820405").unwrap(); +//! assert_eq!(output, e.into_writer().into_inner()) //! ``` use crate::types::{Tag, Type}; @@ -727,7 +721,7 @@ mod tests { where F: FnMut(Encoder>) -> EncodeResult, { - let mut buffer = vec![0u8; 128]; + let mut buffer = [0u8; 128]; assert!(f(Encoder::new(Cursor::new(&mut buffer[..]))).is_ok()); assert_eq!( &hex::decode(expected).unwrap()[..], diff --git a/crates/cbor-codec/src/lib.rs b/crates/cbor-codec/src/lib.rs index d744417..bef6e11 100644 --- a/crates/cbor-codec/src/lib.rs +++ b/crates/cbor-codec/src/lib.rs @@ -12,9 +12,6 @@ pub mod slice; pub mod types; pub mod value; -#[cfg(feature = "random")] -pub mod random; - pub use crate::decoder::{maybe, opt, or_break}; pub use crate::decoder::{Config, DecodeError, DecodeResult, Decoder, GenericDecoder}; pub use crate::encoder::{EncodeError, EncodeResult, Encoder, GenericEncoder}; diff --git a/crates/cbor-codec/src/random.rs b/crates/cbor-codec/src/random.rs deleted file mode 100644 index 16195ba..0000000 --- a/crates/cbor-codec/src/random.rs +++ /dev/null @@ -1,172 +0,0 @@ -// This Source Code Form is subject to the terms of -// the Mozilla Public License, v. 2.0. If a copy of -// the MPL was not distributed with this file, You -// can obtain one at http://mozilla.org/MPL/2.0/. - -//! Generate random `cbor::Value`s. -//! -//! This module is only available with `--features="random"`. - -use quickcheck::{Arbitrary, Gen}; -use std::collections::{BTreeMap, LinkedList}; -use types::Tag; -use value::{Int, Value, Simple, Key, Bytes, Text}; - -/// Generate a random `cbor::Value`. -/// Mostly useful for quickcheck related tests. -/// The parameter `level` denotes the maximum nesting of this value. -pub fn gen_value(level: u16, g: &mut G) -> Value { - match g.gen_range(0, 20) { - 0 => Value::Null, - 1 => Value::Undefined, - 2 => Value::U8(g.gen()), - 3 => Value::U16(g.gen()), - 4 => Value::U32(g.gen()), - 5 => Value::U64(g.gen()), - 6 => Value::I8(g.gen()), - 7 => Value::I16(g.gen()), - 8 => Value::I32(g.gen()), - 9 => Value::I64(g.gen()), - 10 => Value::F32(g.gen()), - 11 => Value::F64(g.gen()), - 12 => Value::Text(gen_text(g)), - 13 => Value::Bytes(gen_bytes(g)), - 14 => Value::Array( - if level > 0 { - gen_array(level - 1, g) - } else { - Vec::with_capacity(0) - }), - 15 => Value::Bool(g.gen()), - 16 => Value::Simple(gen_simple(g)), - 17 => Value::Map( - if level > 0 { - gen_map(level - 1, g) - } else { - BTreeMap::new() - }), - 18 => Value::Int(gen_int(g)), - _ => gen_tagged(g) - } -} - -fn gen_array(level: u16, g: &mut G) -> Vec { - let len = g.gen_range(0, 64); - let mut vec = Vec::with_capacity(len); - for _ in 0 .. len { - vec.push(gen_value(level, g)) - } - vec -} - -fn gen_map(level: u16, g: &mut G) -> BTreeMap { - let len = g.gen_range(0, 64); - let mut map = BTreeMap::new(); - for _ in 0 .. len { - map.insert(gen_key(g), gen_value(level, g)); - } - map -} - -fn gen_key(g: &mut G) -> Key { - match g.gen_range(0, 4) { - 0 => Key::Int(gen_int(g)), - 1 => Key::Text(gen_text(g)), - 2 => Key::Bytes(gen_bytes(g)), - _ => Key::Bool(g.gen()), - } -} - -fn gen_int(g: &mut G) -> Int { - if g.gen() { - Int::Pos(g.gen()) - } else { - Int::Neg(g.gen()) - } -} - -fn gen_tag(g: &mut G) -> Tag { - match g.gen_range(0, 20) { - 0 => Tag::DateTime, - 1 => Tag::Timestamp, - 2 => Tag::Bignum, - 3 => Tag::NegativeBignum, - 4 => Tag::Decimal, - 5 => Tag::Bigfloat, - 6 => Tag::ToBase64Url, - 7 => Tag::ToBase64, - 8 => Tag::ToBase16, - 9 => Tag::Cbor, - 10 => Tag::Uri, - 11 => Tag::Base64Url, - 12 => Tag::Base64, - 13 => Tag::Regex, - 14 => Tag::Mime, - 15 => Tag::CborSelf, - tg => Tag::Unassigned(tg) - } -} - -fn gen_text(g: &mut G) -> Text { - match g.gen() { - true => Text::Text(Arbitrary::arbitrary(g)), - false => Text::Chunks(gen_chunks(g)) - } -} - -fn gen_bytes(g: &mut G) -> Bytes { - match g.gen() { - true => Bytes::Bytes(Arbitrary::arbitrary(g)), - false => Bytes::Chunks(gen_chunks(g)) - } -} - -fn gen_chunks(g: &mut G) -> LinkedList { - let mut xs = LinkedList::new(); - for _ in 0 .. g.gen_range(0, 64) { - xs.push_back(Arbitrary::arbitrary(g)) - } - xs -} - -fn gen_simple(g: &mut G) -> Simple { - match g.gen() { - true => match g.gen() { - n @ 0u8...19 | n @ 28...30 => Simple::Unassigned(n), - n @ 32...255 => Simple::Unassigned(n), - _ => Simple::Unassigned(0) - }, - false => match g.gen() { - n @ 0u8...31 => Simple::Reserved(n), - _ => Simple::Reserved(0) - } - } -} - -fn gen_tagged(g: &mut G) -> Value { - match gen_tag(g) { - t@Tag::DateTime => Value::Tagged(t, Box::new(Value::Text(gen_text(g)))), - t@Tag::Timestamp => match g.gen_range(0, 10) { - 0 => Value::Tagged(t, Box::new(Value::U8(g.gen()))), - 1 => Value::Tagged(t, Box::new(Value::U16(g.gen()))), - 2 => Value::Tagged(t, Box::new(Value::U32(g.gen()))), - 3 => Value::Tagged(t, Box::new(Value::U64(g.gen()))), - 4 => Value::Tagged(t, Box::new(Value::I8(g.gen()))), - 5 => Value::Tagged(t, Box::new(Value::I16(g.gen()))), - 6 => Value::Tagged(t, Box::new(Value::I32(g.gen()))), - 7 => Value::Tagged(t, Box::new(Value::I64(g.gen()))), - 8 => Value::Tagged(t, Box::new(Value::F32(g.gen()))), - _ => Value::Tagged(t, Box::new(Value::F64(g.gen()))) - }, - t@Tag::Bignum => Value::Tagged(t, Box::new(Value::Bytes(gen_bytes(g)))), - t@Tag::NegativeBignum => Value::Tagged(t, Box::new(Value::Bytes(gen_bytes(g)))), - t@Tag::Uri => Value::Tagged(t, Box::new(Value::Text(gen_text(g)))), - t@Tag::Base64 => Value::Tagged(t, Box::new(Value::Text(gen_text(g)))), - t@Tag::ToBase64Url => Value::Tagged(t, Box::new(Value::Text(gen_text(g)))), - t@Tag::Regex => Value::Tagged(t, Box::new(Value::Text(gen_text(g)))), - t@Tag::Decimal => Value::Tagged(t, Box::new(Value::Array(vec![Value::U64(g.gen()), Value::U64(g.gen())]))), - t@Tag::Bigfloat => Value::Tagged(t, Box::new(Value::Array(vec![Value::U64(g.gen()), Value::U64(g.gen())]))), - _ => Value::Tagged(Tag::Mime, Box::new(Value::Text(gen_text(g)))) - } -} - diff --git a/crates/cbor-codec/src/skip.rs b/crates/cbor-codec/src/skip.rs index 1b21da3..b42a93b 100644 --- a/crates/cbor-codec/src/skip.rs +++ b/crates/cbor-codec/src/skip.rs @@ -5,8 +5,7 @@ //! `Skip` trait to allow efficient skipping of consecutive bytes. -use std::i64; -use std::io::{Result, Error, ErrorKind, Seek, SeekFrom}; +use std::io::{Error, ErrorKind, Result, Seek, SeekFrom}; /// Type which supports skipping a number of bytes. /// @@ -21,7 +20,7 @@ impl Skip for A { /// `n` must be in range `[0, i64::MAX]`. fn skip(&mut self, n: u64) -> Result<()> { if n > i64::MAX as u64 { - return Err(Error::new(ErrorKind::Other, "n too large")) + return Err(Error::new(ErrorKind::Other, "n too large")); } self.seek(SeekFrom::Current(n as i64)).and(Ok(())) } diff --git a/crates/cbor-codec/src/value.rs b/crates/cbor-codec/src/value.rs index e6244de..5900d54 100644 --- a/crates/cbor-codec/src/value.rs +++ b/crates/cbor-codec/src/value.rs @@ -10,7 +10,6 @@ use crate::types::Tag; use std::collections::{BTreeMap, LinkedList}; -use std::i64; /// The generic CBOR representation. #[derive(Clone, Debug, PartialEq, PartialOrd)] diff --git a/crates/cbor-codec/tests/unit.rs b/crates/cbor-codec/tests/unit.rs index ec435f0..30f4022 100644 --- a/crates/cbor-codec/tests/unit.rs +++ b/crates/cbor-codec/tests/unit.rs @@ -105,8 +105,8 @@ fn eq(a: &Json, b: &Value) -> bool { match (a, b) { (&Json::Null, &Value::Null) => true, (&Json::Bool(x), &Value::Bool(y)) => x == y, - (&Json::String(ref x), &Value::Text(Text::Text(ref y))) => x == y, - (&Json::String(ref x), &Value::Text(Text::Chunks(ref y))) => { + (Json::String(x), &Value::Text(Text::Text(ref y))) => x == y, + (Json::String(x), &Value::Text(Text::Chunks(ref y))) => { let mut s = String::new(); for c in y { s.push_str(c) @@ -116,10 +116,8 @@ fn eq(a: &Json, b: &Value) -> bool { (&Json::Number(x), y) => util::as_f64(y) .map(|i| (x - i).abs() < f64::EPSILON) .unwrap_or(false), - (&Json::Array(ref x), &Value::Array(ref y)) => { - x.iter().zip(y.iter()).all(|(xi, yi)| eq(xi, yi)) - } - (&Json::Object(ref x), &Value::Map(ref y)) => { + (Json::Array(x), Value::Array(y)) => x.iter().zip(y.iter()).all(|(xi, yi)| eq(xi, yi)), + (Json::Object(x), Value::Map(y)) => { for (k, v) in x { if let Some(w) = y.get(&Key::Text(Text::Text(k.clone()))) { if !eq(v, w) { diff --git a/src/identity.rs b/src/identity.rs index 903d81c..3ea8ecb 100644 --- a/src/identity.rs +++ b/src/identity.rs @@ -30,8 +30,8 @@ pub enum IdentityMode { #[derive(Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Identity<'r> { - Sec(Cow<'r, IdentityKeyPair>), - Pub(Cow<'r, IdentityKey>), + Sec(Cow<'r, Box>), + Pub(Cow<'r, Box>), } impl<'r> Identity<'r> { @@ -73,8 +73,9 @@ impl<'r> Identity<'r> { if keypair.is_some() { return Err(DecodeError::DuplicateField("identity keypair")); } else { - keypair = - Some(Identity::Sec(Cow::Owned(IdentityKeyPair::decode(d)?))) + keypair = Some(Identity::Sec(Cow::Owned(Box::new( + IdentityKeyPair::decode(d)?, + )))) } } _ => d.skip()?, @@ -91,7 +92,9 @@ impl<'r> Identity<'r> { if key.is_some() { return Err(DecodeError::DuplicateField("identity key")); } else { - key = Some(Identity::Pub(Cow::Owned(IdentityKey::decode(d)?))) + key = Some(Identity::Pub(Cow::Owned(Box::new( + IdentityKey::decode(d)?, + )))) } } _ => d.skip()?, @@ -114,7 +117,7 @@ mod tests { #[wasm_bindgen_test] fn enc_dec_identity_sec() { let k = IdentityKeyPair::new(); - let identity = Identity::Sec(std::borrow::Cow::Owned(k)); + let identity = Identity::Sec(std::borrow::Cow::Owned(Box::new(k))); let r = roundtrip( |mut e| identity.encode(&mut e), |mut d| Identity::decode(&mut d), @@ -126,7 +129,7 @@ mod tests { #[wasm_bindgen_test] fn enc_dec_identity_pub() { let k = IdentityKeyPair::new(); - let identity = Identity::Pub(std::borrow::Cow::Owned(k.public_key)); + let identity = Identity::Pub(std::borrow::Cow::Owned(Box::new(k.public_key))); let r = roundtrip( |mut e| identity.encode(&mut e), |mut d| Identity::decode(&mut d), diff --git a/src/internal/keys.rs b/src/internal/keys.rs index 5d9c432..55b9ad0 100644 --- a/src/internal/keys.rs +++ b/src/internal/keys.rs @@ -151,8 +151,7 @@ impl IdentityKeyPair { } #[cfg(feature = "hazmat")] - #[must_use] - pub unsafe fn from_raw_key_pair(sk: [u8; 64], pk: [u8; 32]) -> ProteusResult { + pub fn from_raw_key_pair(sk: [u8; 64], pk: [u8; 32]) -> ProteusResult { Ok(Self::from_keypair(KeyPair::from_raw(sk, pk)?)) } } @@ -449,8 +448,7 @@ impl KeyPair { } #[cfg(feature = "hazmat")] - #[must_use] - pub unsafe fn from_raw(sk: [u8; 64], pk: [u8; 32]) -> ProteusResult { + pub fn from_raw(sk: [u8; 64], pk: [u8; 32]) -> ProteusResult { let sk = ed25519_dalek::SigningKey::from_keypair_bytes(&sk)?; let pk = ed25519_dalek::VerifyingKey::from_bytes(&pk)?; let secret_key = SecretKey(sk); @@ -627,7 +625,7 @@ impl PublicKey { ) -> bool { let messages: Vec<&[u8]> = verifying_contents.values().map(|m| m.as_slice()).collect(); let signatures: Vec<_> = verifying_contents.keys().map(|s| s.0).collect(); - let verifying_keys: Vec<_> = (0..signatures.len()).map(|_| self.0.clone()).collect(); + let verifying_keys: Vec<_> = (0..signatures.len()).map(|_| self.0).collect(); ed25519_dalek::verify_batch(&messages, &signatures, &verifying_keys).is_ok() } @@ -684,7 +682,7 @@ impl PublicKey { } } let pub_edward = pub_edward.ok_or(DecodeError::MissingField("PublicKey::pub_edward"))?; - Ok(Self(ed25519_dalek::VerifyingKey::from_bytes(&*pub_edward)?)) + Ok(Self(ed25519_dalek::VerifyingKey::from_bytes(&pub_edward)?)) } } diff --git a/src/internal/session.rs b/src/internal/session.rs index 39f0b6f..1cf78f8 100644 --- a/src/internal/session.rs +++ b/src/internal/session.rs @@ -215,7 +215,7 @@ impl RecvChain { ) -> SessionResult, E> { let too_old = self .message_keys - .get(0) + .front() .map_or(false, |k| k.counter > mesg.counter); if too_old { @@ -225,10 +225,11 @@ impl RecvChain { let Some(i) = self .message_keys .iter() - .position(|mk| mk.counter == mesg.counter) else { - // ? Handles error case 209 - return Err(SessionError::DuplicateMessage); - }; + .position(|mk| mk.counter == mesg.counter) + else { + // ? Handles error case 209 + return Err(SessionError::DuplicateMessage); + }; // SAFETY: Indexing directly is safe as the `position` check above ensure we have a MessageKeys present at the index if !env.verify(&self.message_keys[i].mac_key) { @@ -727,7 +728,7 @@ impl> Session { 2 => { let li = IdentityKey::decode(d)?; if ident.borrow().public_key != li { - return Err(DecodeError::LocalIdentityChanged(li)); + return Err(DecodeError::LocalIdentityChanged(Box::new(li))); } } 3 if remote_identity.is_none() => remote_identity = Some(IdentityKey::decode(d)?), @@ -1085,7 +1086,6 @@ mod tests { use std::borrow::Borrow; use std::collections::BTreeMap; use std::fmt; - use std::usize; use std::vec::Vec; use wasm_bindgen_test::wasm_bindgen_test; diff --git a/src/internal/types.rs b/src/internal/types.rs index 8fd1d5c..e282464 100644 --- a/src/internal/types.rs +++ b/src/internal/types.rs @@ -95,7 +95,7 @@ pub enum DecodeError { #[error("CBOR array length mismatch: expected {expected}, got {got}")] InvalidArrayLen { expected: usize, got: usize }, #[error("Local identity changed")] - LocalIdentityChanged(IdentityKey), + LocalIdentityChanged(Box), #[error(transparent)] Ed25519Error(#[from] ed25519_dalek::SignatureError), #[error("Unknown message type {0}: {1}")] diff --git a/tests/common.rs b/tests/common.rs index 4fb0e7c..12a5795 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -107,6 +107,12 @@ macro_rules! impl_harness_for_crate { >, } + impl Default for $client { + fn default() -> Self { + Self::new() + } + } + impl $client { #[must_use] pub fn new() -> Self { @@ -363,9 +369,7 @@ impl LegacyClient { impl Client { pub fn from_raw(sk: [u8; 64], pk: [u8; 32]) -> Self { Client { - identity: unsafe { - proteus_wasm::keys::IdentityKeyPair::from_raw_key_pair(sk, pk).unwrap() - }, + identity: proteus_wasm::keys::IdentityKeyPair::from_raw_key_pair(sk, pk).unwrap(), prekeys: Default::default(), sessions: Default::default(), } diff --git a/tests/interop.rs b/tests/interop.rs index 6c387b6..de69e80 100644 --- a/tests/interop.rs +++ b/tests/interop.rs @@ -75,8 +75,9 @@ mod serialization { let (alice, alice_legacy) = get_client_pair(); let identity_legacy = cryptobox::Identity::Sec(std::borrow::Cow::Owned(alice_legacy.identity.clone())); - let identity = - proteus_wasm::identity::Identity::Sec(std::borrow::Cow::Owned(alice.identity.clone())); + let identity = proteus_wasm::identity::Identity::Sec(std::borrow::Cow::Owned(Box::new( + alice.identity.clone(), + ))); let identity_legacy_ser = identity_legacy.serialise().unwrap(); let identity_ser = identity.serialise().unwrap(); @@ -84,11 +85,13 @@ mod serialization { assert_eq!(identity_legacy_ser, identity_ser); let cryptobox::Identity::Sec(identity_new_into_legacy) = - cryptobox::Identity::deserialise(&identity_ser).unwrap() else { + cryptobox::Identity::deserialise(&identity_ser).unwrap() + else { panic!("Wrong identity type: 2.0 -> 1.0"); }; let proteus_wasm::identity::Identity::Sec(identity_legacy_into_new) = - proteus_wasm::identity::Identity::deserialise(&identity_legacy_ser).unwrap() else { + proteus_wasm::identity::Identity::deserialise(&identity_legacy_ser).unwrap() + else { panic!("Wrong identity type: 1.0 -> 2.0") }; @@ -238,7 +241,7 @@ mod communication { assert_eq!(hello_bob, MSG); let hello_alice_from_bob = &bob.encrypt("ba", MSG); - let decrypted = alice.decrypt("ab", &hello_alice_from_bob); + let decrypted = alice.decrypt("ab", hello_alice_from_bob); assert_eq!(decrypted, MSG); }