From 619dc620fac0c91ca8bddbf5a6e77a8cf1385586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 14 Oct 2024 15:21:12 +0300 Subject: [PATCH 1/2] Remove `alloc` crate feature from `concat-kdf` and `ansi-x963-kdf` --- ansi-x963-kdf/Cargo.toml | 3 -- ansi-x963-kdf/src/lib.rs | 76 +++++++++++++--------------------------- concat-kdf/Cargo.toml | 3 -- concat-kdf/src/lib.rs | 69 +++++++++++------------------------- 4 files changed, 45 insertions(+), 106 deletions(-) diff --git a/ansi-x963-kdf/Cargo.toml b/ansi-x963-kdf/Cargo.toml index f1bee58..008c0c0 100644 --- a/ansi-x963-kdf/Cargo.toml +++ b/ansi-x963-kdf/Cargo.toml @@ -19,9 +19,6 @@ digest = "=0.11.0-pre.9" hex-literal = "0.4" sha2 = { version = "=0.11.0-pre.4", default-features = false } -[features] -alloc = [] - [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/ansi-x963-kdf/src/lib.rs b/ansi-x963-kdf/src/lib.rs index a36f587..6a54991 100644 --- a/ansi-x963-kdf/src/lib.rs +++ b/ansi-x963-kdf/src/lib.rs @@ -5,35 +5,6 @@ use core::fmt; use digest::{array::typenum::Unsigned, Digest, FixedOutputReset}; -#[cfg(feature = "alloc")] -extern crate alloc; - -/// ANSI-X9.63 KDF errors. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum Error { - /// The length of the secret is zero. - NoSecret, - /// The length of the output is zero. - NoOutput, - /// The length of the input is too big - InputOverflow, - /// The length of the output is too big. - CounterOverflow, -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - f.write_str(match self { - Error::NoSecret => "Buffer for secret has zero length.", - Error::NoOutput => "Buffer for key has zero length.", - Error::InputOverflow => "Input length is to big.", - Error::CounterOverflow => "Requested key length is to big.", - }) - } -} - -impl ::core::error::Error for Error {} - /// Derives `key` in-place from `secret` and `shared_info`. /// /// # Example @@ -90,27 +61,28 @@ where Ok(()) } -/// Derives and returns `length` bytes key from `secret` and `shared_info`. -/// -/// # Example -/// ``` -/// use hex_literal::hex; -/// use sha2::Sha256; -/// -/// let key = ansi_x963_kdf::derive_key::(b"secret", b"shared-info", 16).unwrap(); -/// assert_eq!(key[..], hex!("8dbb1d50bcc7fc782abc9db5c64a2826")[..]); -/// ``` -#[cfg(feature = "alloc")] -#[inline] -pub fn derive_key( - secret: &[u8], - shared_info: &[u8], - length: usize, -) -> Result, Error> -where - D: Digest + FixedOutputReset, -{ - let mut key = alloc::vec![0u8; length].into_boxed_slice(); - derive_key_into::(secret, shared_info, &mut key)?; - Ok(key) +/// ANSI-X9.63 KDF errors. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Error { + /// The length of the secret is zero. + NoSecret, + /// The length of the output is zero. + NoOutput, + /// The length of the input is too big + InputOverflow, + /// The length of the output is too big. + CounterOverflow, } + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + f.write_str(match self { + Error::NoSecret => "Buffer for secret has zero length.", + Error::NoOutput => "Buffer for key has zero length.", + Error::InputOverflow => "Input length is to big.", + Error::CounterOverflow => "Requested key length is to big.", + }) + } +} + +impl core::error::Error for Error {} diff --git a/concat-kdf/Cargo.toml b/concat-kdf/Cargo.toml index af3bd93..f24c9ae 100644 --- a/concat-kdf/Cargo.toml +++ b/concat-kdf/Cargo.toml @@ -19,9 +19,6 @@ digest = "=0.11.0-pre.9" hex-literal = "0.4" sha2 = { version = "=0.11.0-pre.4", default-features = false } -[features] -alloc = [] - [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/concat-kdf/src/lib.rs b/concat-kdf/src/lib.rs index a14e222..f42731e 100644 --- a/concat-kdf/src/lib.rs +++ b/concat-kdf/src/lib.rs @@ -5,32 +5,6 @@ use core::fmt; use digest::{array::typenum::Unsigned, Digest, FixedOutputReset, Update}; -#[cfg(feature = "alloc")] -extern crate alloc; - -/// Concat KDF errors. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum Error { - /// The length of the secret is zero. - NoSecret, - /// The length of the output is zero. - NoOutput, - /// The length of the output is too big. - CounterOverflow, -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - f.write_str(match self { - Error::NoSecret => "Buffer for secret has zero length.", - Error::NoOutput => "Buffer for key has zero length.", - Error::CounterOverflow => "Requested key length is to big.", - }) - } -} - -impl ::core::error::Error for Error {} - /// Derives `key` in-place from `secret` and `other_info`. /// /// # Example @@ -73,26 +47,25 @@ where Ok(()) } -/// Derives and returns `length` bytes key from `secret` and `other_info`. -/// -/// # Example -/// ```rust -/// use hex_literal::hex; -/// use sha2::Sha256; -/// -/// let key = concat_kdf::derive_key::(b"secret", b"shared-info", 16).unwrap(); -/// assert_eq!(key[..], hex!("960db2c549ab16d71a7b008e005c2bdc")[..]); -/// ``` -#[cfg(feature = "alloc")] -pub fn derive_key( - secret: &[u8], - other_info: &[u8], - length: usize, -) -> Result, Error> -where - D: Digest + FixedOutputReset, -{ - let mut key = alloc::vec![0u8; length].into_boxed_slice(); - derive_key_into::(secret, other_info, &mut key)?; - Ok(key) +/// Concat KDF errors. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Error { + /// The length of the secret is zero. + NoSecret, + /// The length of the output is zero. + NoOutput, + /// The length of the output is too big. + CounterOverflow, } + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + f.write_str(match self { + Error::NoSecret => "Buffer for secret has zero length.", + Error::NoOutput => "Buffer for key has zero length.", + Error::CounterOverflow => "Requested key length is to big.", + }) + } +} + +impl core::error::Error for Error {} From 7b169a80b84196b82491ec5a30b24e3f18dae2b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 14 Oct 2024 15:24:07 +0300 Subject: [PATCH 2/2] Remove `doc_auto_cfg` --- ansi-x963-kdf/Cargo.toml | 5 ----- ansi-x963-kdf/src/lib.rs | 1 - concat-kdf/Cargo.toml | 4 ---- concat-kdf/src/lib.rs | 1 - 4 files changed, 11 deletions(-) diff --git a/ansi-x963-kdf/Cargo.toml b/ansi-x963-kdf/Cargo.toml index 008c0c0..e4e20ae 100644 --- a/ansi-x963-kdf/Cargo.toml +++ b/ansi-x963-kdf/Cargo.toml @@ -18,8 +18,3 @@ digest = "=0.11.0-pre.9" [dev-dependencies] hex-literal = "0.4" sha2 = { version = "=0.11.0-pre.4", default-features = false } - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] - diff --git a/ansi-x963-kdf/src/lib.rs b/ansi-x963-kdf/src/lib.rs index 6a54991..6d0e7bc 100644 --- a/ansi-x963-kdf/src/lib.rs +++ b/ansi-x963-kdf/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![doc = include_str!("../README.md")] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] use core::fmt; use digest::{array::typenum::Unsigned, Digest, FixedOutputReset}; diff --git a/concat-kdf/Cargo.toml b/concat-kdf/Cargo.toml index f24c9ae..b7cf056 100644 --- a/concat-kdf/Cargo.toml +++ b/concat-kdf/Cargo.toml @@ -18,7 +18,3 @@ digest = "=0.11.0-pre.9" [dev-dependencies] hex-literal = "0.4" sha2 = { version = "=0.11.0-pre.4", default-features = false } - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] diff --git a/concat-kdf/src/lib.rs b/concat-kdf/src/lib.rs index f42731e..a355bed 100644 --- a/concat-kdf/src/lib.rs +++ b/concat-kdf/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![doc = include_str!("../README.md")] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] use core::fmt; use digest::{array::typenum::Unsigned, Digest, FixedOutputReset, Update};