From f5ff4a08d931b617e1b8e60d4bec1f6288c0a79e Mon Sep 17 00:00:00 2001 From: Messjer Date: Sat, 18 Aug 2018 22:03:27 +0800 Subject: [PATCH] Refactor: made the module `basic` private. This design decision is aimed at making unrelated innerworkings invisible to users. Necessary interfaces can be reopened by `pub use`, see e.g. `sm2/mod.rs`. --- src/basic/util.rs | 21 ++++++--------------- src/lib.rs | 2 +- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/basic/util.rs b/src/basic/util.rs index d993a75..2dbdd15 100644 --- a/src/basic/util.rs +++ b/src/basic/util.rs @@ -3,15 +3,12 @@ /// Convert bytes into `[u32]` blocks for internal representations. /// /// ## Example -/// ``` -/// extern crate yogcrypt; -/// use yogcrypt::basic::util::bytes_to_u32_blocks; -/// +/// `` /// let msg = b"abcde"; /// let (msg, bit_len) = bytes_to_u32_blocks(msg); /// assert_eq!(msg, vec![0x61626364, 0x65000000]); /// assert_eq!(bit_len, 40); -/// ``` +/// `` pub fn bytes_to_u32_blocks(msg: &[u8]) -> (Vec, usize) { // bit length = msg.len() * 8 let bit_len = msg.len() << 3; @@ -41,14 +38,11 @@ pub fn bytes_to_u32_blocks(msg: &[u8]) -> (Vec, usize) { /// Converts representation of 128-bit number from `[u8;16]` to blocks of `[u32;8]`. /// /// ## Example -/// ``` -/// extern crate yogcrypt; -/// use yogcrypt::basic::util::bytes_to_four_u32; -/// +/// `` /// let key = b"Hello, World!123"; /// let u32_blocks = bytes_to_four_u32(key); /// assert_eq!(u32_blocks, [1214606444, 1865162839, 1869769828, 556872243]); -/// ``` +/// `` pub fn bytes_to_four_u32(b: &[u8; 16]) -> [u32; 4] { [ (u32::from(b[0]) << 24) @@ -73,14 +67,11 @@ pub fn bytes_to_four_u32(b: &[u8; 16]) -> [u32; 4] { /// Converts representation of 128-bit number from `[u32;8]` to blocks of `[u8;16]`. /// /// ## Example -/// ``` -/// extern crate yogcrypt; -/// use yogcrypt::basic::util::four_u32_to_bytes; -/// +/// `` /// let u32_blocks = [1214606444, 1865162839, 1869769828, 556872243]; /// let key = four_u32_to_bytes(&u32_blocks); /// assert_eq!(&key, b"Hello, World!123"); -/// ``` +/// `` pub fn four_u32_to_bytes(l: &[u32; 4]) -> [u8; 16] { [ (l[0] >> 24) as u8, diff --git a/src/lib.rs b/src/lib.rs index fbd6a1b..e2da55e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ extern crate rand; #[macro_use] extern crate lazy_static; -pub mod basic; +mod basic; pub mod sm2; pub mod sm3; pub mod sm4;