diff --git a/src/edwards.rs b/src/edwards.rs index ce6599f..d80392d 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -1410,10 +1410,18 @@ mod test { let enc_compressed = bincode::serialize(&constants::ED25519_BASEPOINT_COMPRESSED).unwrap(); assert_eq!(encoded, enc_compressed); + // Check that the encoding is 32 bytes exactly + assert_eq!(encoded.len(), 32); + let dec_uncompressed: EdwardsPoint = bincode::deserialize(&encoded).unwrap(); let dec_compressed: CompressedEdwardsY = bincode::deserialize(&encoded).unwrap(); assert_eq!(dec_uncompressed, constants::ED25519_BASEPOINT_POINT); assert_eq!(dec_compressed, constants::ED25519_BASEPOINT_COMPRESSED); + + // Check that the encoding itself matches the usual one + let raw_bytes = constants::ED25519_BASEPOINT_COMPRESSED.as_bytes(); + let bp: EdwardsPoint = bincode::deserialize(raw_bytes).unwrap(); + assert_eq!(bp, constants::ED25519_BASEPOINT_POINT); } } diff --git a/src/ristretto.rs b/src/ristretto.rs index e4c1e81..5d0be03 100644 --- a/src/ristretto.rs +++ b/src/ristretto.rs @@ -1092,11 +1092,19 @@ mod test { let enc_compressed = bincode::serialize(&constants::RISTRETTO_BASEPOINT_COMPRESSED).unwrap(); assert_eq!(encoded, enc_compressed); + // Check that the encoding is 32 bytes exactly + assert_eq!(encoded.len(), 32); + let dec_uncompressed: RistrettoPoint = bincode::deserialize(&encoded).unwrap(); let dec_compressed: CompressedRistretto = bincode::deserialize(&encoded).unwrap(); assert_eq!(dec_uncompressed, constants::RISTRETTO_BASEPOINT_POINT); assert_eq!(dec_compressed, constants::RISTRETTO_BASEPOINT_COMPRESSED); + + // Check that the encoding itself matches the usual one + let raw_bytes = constants::RISTRETTO_BASEPOINT_COMPRESSED.as_bytes(); + let bp: RistrettoPoint = bincode::deserialize(raw_bytes).unwrap(); + assert_eq!(bp, constants::RISTRETTO_BASEPOINT_POINT); } #[test] diff --git a/src/scalar.rs b/src/scalar.rs index 6f9d52b..86085ac 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -1649,9 +1649,18 @@ mod test { #[cfg(feature = "serde")] fn serde_bincode_scalar_roundtrip() { use bincode; - let output = bincode::serialize(&X).unwrap(); - let parsed: Scalar = bincode::deserialize(&output).unwrap(); + let encoded = bincode::serialize(&X).unwrap(); + let parsed: Scalar = bincode::deserialize(&encoded).unwrap(); assert_eq!(parsed, X); + + // Check that the encoding is 32 bytes exactly + assert_eq!(encoded.len(), 32); + + // Check that the encoding itself matches the usual one + assert_eq!( + X, + bincode::deserialize(X.as_bytes()).unwrap(), + ); } #[cfg(debug_assertions)]