diff options
author | Brian Warner <warner@lothar.com> | 2018-12-06 14:54:25 -0800 |
---|---|---|
committer | Brian Warner <warner@lothar.com> | 2018-12-06 14:54:25 -0800 |
commit | c4cbd555a7e58c11187bedfebca1614b16765188 (patch) | |
tree | 07de09620c347dd673ba6e4b76bf9a2dc2d6b7fa | |
parent | f711998adedff93810590ee10b652c4fa3d4e66b (diff) | |
parent | f826bdbf54d1610383b453f9d5ccfc609455d714 (diff) | |
download | PAKEs-c4cbd555a7e58c11187bedfebca1614b16765188.tar.xz |
spake2: Merge PR11: better Debug impl
-rw-r--r-- | spake2/src/lib.rs | 22 | ||||
-rw-r--r-- | spake2/src/tests.rs | 7 |
2 files changed, 20 insertions, 9 deletions
diff --git a/spake2/src/lib.rs b/spake2/src/lib.rs index 07fb4df..0bcfd6d 100644 --- a/spake2/src/lib.rs +++ b/spake2/src/lib.rs @@ -358,6 +358,7 @@ pub trait Group { // const element_length: usize; // in unstable, or u8 //type ElementBytes : Index<usize, Output=u8>+IndexMut<usize>; // later type TranscriptHash; + fn name() -> &'static str; fn const_m() -> Self::Element; fn const_n() -> Self::Element; fn const_s() -> Self::Element; @@ -385,6 +386,10 @@ impl Group for Ed25519Group { //type ScalarBytes type TranscriptHash = Sha256; + fn name() -> &'static str { + "Ed25519" + } + fn const_m() -> c2_Element { // python -c "import binascii, spake2; b=binascii.hexlify(spake2.ParamsEd25519.M.to_bytes()); print(', '.join(['0x'+b[i:i+2] for i in range(0,len(b),2)]))" // 15cfd18e385952982b6a8f8c7854963b58e34388c8e6dae891db756481a02312 @@ -820,15 +825,14 @@ fn maybe_utf8(s: &[u8]) -> String { } impl<G: Group> fmt::Debug for SPAKE2<G> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "SPAKE2(G=?, side={:?}, idA={}, idB={}, idS={})", - self.side, - maybe_utf8(&self.id_a), - maybe_utf8(&self.id_b), - maybe_utf8(&self.id_s) - ) + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("SPAKE2") + .field("group", &G::name()) + .field("side", &self.side) + .field("idA", &maybe_utf8(&self.id_a)) + .field("idB", &maybe_utf8(&self.id_b)) + .field("idS", &maybe_utf8(&self.id_s)) + .finish() } } diff --git a/spake2/src/tests.rs b/spake2/src/tests.rs index b94bcdd..0328266 100644 --- a/spake2/src/tests.rs +++ b/spake2/src/tests.rs @@ -185,9 +185,16 @@ fn test_debug() { &Identity::new(b"idB"), ); println!("s1: {:?}", s1); + assert_eq!( + format!("{:?}", s1), + "SPAKE2 { group: \"Ed25519\", side: A, idA: \"(s=idA)\", idB: \"(s=idB)\", idS: \"(s=)\" }" + ); + let (s2, _msg1) = SPAKE2::<Ed25519Group>::start_symmetric( &Password::new(b"password"), &Identity::new(b"idS"), ); println!("s2: {:?}", s2); + assert_eq!(format!("{:?}", s2), + "SPAKE2 { group: \"Ed25519\", side: Symmetric, idA: \"(s=)\", idB: \"(s=)\", idS: \"(s=idS)\" }"); } |