From ce1d97002c7b979495286477924c1e6d05db5c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Wed, 10 Jun 2020 16:38:49 -0400 Subject: [PATCH 1/2] cleaner to_bytes() for a few structures --- src/opaque.rs | 14 +++++++------- src/tests/serialization.rs | 9 ++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/opaque.rs b/src/opaque.rs index 20f698c..2792813 100644 --- a/src/opaque.rs +++ b/src/opaque.rs @@ -112,10 +112,11 @@ where KeyFormat: KeyPair, { pub fn to_bytes(&self) -> Vec { - let mut res = Vec::new(); - res.extend(self.envelope.to_bytes()); - res.extend(self.client_s_pk.to_arr()); - res + [ + &self.envelope.to_bytes(), + self.client_s_pk.to_arr().as_slice(), + ] + .concat() } } @@ -164,12 +165,11 @@ impl TryFrom<&[u8]> for LoginFirstMessage { impl LoginFirstMessage { pub fn to_bytes(&self) -> Vec { - let output: Vec = [ + [ self.alpha.to_bytes().as_slice(), &self.ke1_message.to_bytes(), ] - .concat(); - output + .concat() } } diff --git a/src/tests/serialization.rs b/src/tests/serialization.rs index cf1766c..59dcb22 100644 --- a/src/tests/serialization.rs +++ b/src/tests/serialization.rs @@ -29,9 +29,7 @@ fn client_registration_roundtrip() { let mut rng = OsRng; let sc = ::random_scalar(&mut rng); // serialization order: scalar, password - let mut bytes: Vec = vec![]; - bytes.extend_from_slice(sc.as_bytes()); - bytes.extend_from_slice(pw); + let bytes: Vec = [&sc.as_bytes()[..], &pw[..]].concat(); let reg = ClientRegistration::::try_from(&bytes[..]).unwrap(); let reg_bytes = reg.to_bytes(); assert_eq!(reg_bytes, bytes); @@ -113,10 +111,7 @@ fn register_third_message_roundtrip() { ) .unwrap(); - let mut message = Vec::new(); - message.extend_from_slice(&ciphertext.to_bytes()); - message.extend_from_slice(&pubkey_bytes); - + let message: Vec = [&ciphertext.to_bytes(), &pubkey_bytes[..]].concat(); let r3 = RegisterThirdMessage::::try_from(&message[..]).unwrap(); let r3_bytes = r3.to_bytes(); From cd46a4263470e3073d6840a18a1730d6c0896586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Fri, 12 Jun 2020 18:49:32 -0400 Subject: [PATCH 2/2] Have CI run more often --- .github/workflows/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 04508a3..ba8e250 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,9 @@ name: Rust CI -on: [push] +on: + push: + pull_request: + types: [opened, repoened, synchronize] + jobs: combo: name: test + Clippy + rustfmt