From ae3fbde0a3be5d1a6146e98a0b5245adf9a148f4 Mon Sep 17 00:00:00 2001 From: David Niehues <7667041+DavidNiehues@users.noreply.github.com> Date: Sun, 15 Dec 2024 20:48:11 +0100 Subject: [PATCH] test(fix-doctest): fix doctests where a function is wrapped around a doctest but the function is never called In the doctests in kem.rs, the actual tests that are run to verify that the KyberKem and the DummyKem actually work are wrapped inside a function to make use of the ?-operator. However, these functions were never called and thus the tests weren't really helpful and didn't provide proper coverage. --- Cargo.lock | 1 + cipher-traits/Cargo.toml | 1 + cipher-traits/src/kem.rs | 17 +++++++---------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f2fcdf..13761f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1866,6 +1866,7 @@ dependencies = [ name = "rosenpass-cipher-traits" version = "0.1.0" dependencies = [ + "anyhow", "rosenpass-oqs", "rosenpass-secret-memory", ] diff --git a/cipher-traits/Cargo.toml b/cipher-traits/Cargo.toml index 3ebdfb1..2e9ea32 100644 --- a/cipher-traits/Cargo.toml +++ b/cipher-traits/Cargo.toml @@ -14,3 +14,4 @@ readme = "readme.md" [dev-dependencies] rosenpass-oqs = { workspace = true } rosenpass-secret-memory = { workspace = true } +anyhow = {workspace = true} diff --git a/cipher-traits/src/kem.rs b/cipher-traits/src/kem.rs index f469ee4..3f20fa6 100644 --- a/cipher-traits/src/kem.rs +++ b/cipher-traits/src/kem.rs @@ -19,11 +19,10 @@ //!```rust //! use rosenpass_cipher_traits::Kem; //! use rosenpass_oqs::Kyber512; -//! use rosenpass_secret_memory::Secret; +//! # use rosenpass_secret_memory::{secret_policy_use_only_malloc_secrets, Secret}; //! -//! # fn do_doc_test() -> Result<(), Box> { //! type MyKem = Kyber512; -//! +//! secret_policy_use_only_malloc_secrets(); //! let mut alice_sk: Secret<{ MyKem::SK_LEN }> = Secret::zero(); //! let mut alice_pk: [u8; MyKem::PK_LEN] = [0; MyKem::PK_LEN]; //! MyKem::keygen(alice_sk.secret_mut(), &mut alice_pk)?; @@ -36,8 +35,7 @@ //! MyKem::decaps(alice_shk.secret_mut(), alice_sk.secret_mut(), &mut bob_ct)?; //! //! # assert_eq!(alice_shk.secret(), bob_shk.secret()); -//! # Ok(()) -//! # } +//! # Ok::<(), anyhow::Error>(()) //!``` //! //! Implementing the [Kem]-trait for a KEM is easy. Mostly, you must format the KEM's @@ -109,11 +107,10 @@ //! Ok(()) //! } //! } -//! # use rosenpass_secret_memory::Secret; +//! # use rosenpass_secret_memory::{secret_policy_use_only_malloc_secrets, Secret}; //! # -//! # fn do_doc_test() -> Result<(), Box> { //! # type MyKem = DummyKem; -//! # +//! # secret_policy_use_only_malloc_secrets(); //! # let mut alice_sk: Secret<{ MyKem::SK_LEN }> = Secret::zero(); //! # let mut alice_pk: [u8; MyKem::PK_LEN] = [0; MyKem::PK_LEN]; //! # MyKem::keygen(alice_sk.secret_mut(), &mut alice_pk)?; @@ -126,8 +123,8 @@ //! # MyKem::decaps(alice_shk.secret_mut(), alice_sk.secret_mut(), &mut bob_ct)?; //! # //! # assert_eq!(alice_shk.secret(), bob_shk.secret()); -//! # Ok(()) -//! # } +//! # +//! # Ok::<(), String>(()) //!``` //!