Skip to content

Commit

Permalink
Release version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenbanck committed Aug 10, 2024
1 parent 880ce11 commit ef33f67
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2024-08-10

### Added

- Add `byte_array()` function to the `Random` trait.
- Add missing `rand_u128()`, `rand_i128()` and new `rand_byte_array()` functions to the TLS API.

## [0.2.0] - 2024-08-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
readme = "README.md"
documentation = "https://docs.rs/rand_aes"
repository = "https://github.com/hasenbanck/rand_aes"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
rust-version = "1.80"

Expand Down
17 changes: 17 additions & 0 deletions src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ pub fn rand_u64() -> u64 {
RNG.with(|rng| rng.u64())
}

/// Generates a random `u128` value.
pub fn rand_u128() -> u128 {
RNG.with(|rng| rng.u128())
}

/// Generates a random `usize` value.
pub fn rand_usize() -> usize {
RNG.with(|rng| rng.usize())
Expand All @@ -146,6 +151,11 @@ pub fn rand_i64() -> i64 {
RNG.with(|rng| rng.i64())
}

/// Generates a random `i128` value.
pub fn rand_i128() -> i128 {
RNG.with(|rng| rng.i128())
}

/// Generates a random `isize` value.
pub fn rand_isize() -> isize {
RNG.with(|rng| rng.isize())
Expand Down Expand Up @@ -176,6 +186,13 @@ pub fn rand_fill_bytes(slice: &mut [u8]) {
RNG.with(|rng| rng.fill_bytes(slice))
}

/// Generates an array filled with random bytes.
pub fn rand_byte_array<const N: usize>() -> [u8; N] {
let mut buffer = [0; N];
RNG.with(|rng| rng.fill_bytes(&mut buffer));
buffer
}

/// Generates a random `u8` value in the range of 0..n.
///
/// # Notice
Expand Down
7 changes: 7 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ pub trait Random {
.for_each(|x| *x = self.next() as u8);
}

/// Generates an array filled with random bytes.
fn byte_array<const N: usize>(&self) -> [u8; N] {
let mut buffer = [0; N];
self.fill_bytes(&mut buffer);
buffer
}

/// Generates a random u8 value in the range of 0..n.
///
/// # Notice
Expand Down
14 changes: 13 additions & 1 deletion tests/aes128_ctr128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ test_primitive_integer!(test_prng_u8, u8);
test_primitive_integer!(test_prng_u16, u16);
test_primitive_integer!(test_prng_u32, u32);
test_primitive_integer!(test_prng_u64, u64);
test_primitive_integer!(test_prng_u128, u128);
test_primitive_integer!(test_prng_usize, usize);
test_primitive_integer!(test_prng_i8, i8);
test_primitive_integer!(test_prng_i16, i16);
test_primitive_integer!(test_prng_i32, i32);
test_primitive_integer!(test_prng_i64, i64);
test_primitive_integer!(test_prng_i128, i128);
test_primitive_integer!(test_prng_isize, isize);

#[test]
Expand Down Expand Up @@ -121,14 +123,24 @@ fn test_prng_f64() {
#[test]
fn test_prng_fill_bytes() {
let prng = Aes128Ctr128::from_seed(Aes128Ctr128Seed::default());
let mut bytes = [0u8; 16];
let mut bytes = [0u8; 128];
prng.fill_bytes(&mut bytes);
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_byte_array() {
let prng = Aes128Ctr128::from_seed(Aes128Ctr128Seed::default());
let bytes: [u8; 128] = prng.byte_array();
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_shuffle() {
let prng = Aes128Ctr128::from_seed(Aes128Ctr128Seed::default());
Expand Down
14 changes: 13 additions & 1 deletion tests/aes128_ctr64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ test_primitive_integer!(test_prng_u8, u8);
test_primitive_integer!(test_prng_u16, u16);
test_primitive_integer!(test_prng_u32, u32);
test_primitive_integer!(test_prng_u64, u64);
test_primitive_integer!(test_prng_u128, u128);
test_primitive_integer!(test_prng_usize, usize);
test_primitive_integer!(test_prng_i8, i8);
test_primitive_integer!(test_prng_i16, i16);
test_primitive_integer!(test_prng_i32, i32);
test_primitive_integer!(test_prng_i64, i64);
test_primitive_integer!(test_prng_i128, i128);
test_primitive_integer!(test_prng_isize, isize);

#[test]
Expand Down Expand Up @@ -121,14 +123,24 @@ fn test_prng_f64() {
#[test]
fn test_prng_fill_bytes() {
let prng = Aes128Ctr64::from_seed(Aes128Ctr64Seed::default());
let mut bytes = [0u8; 16];
let mut bytes = [0u8; 128];
prng.fill_bytes(&mut bytes);
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_byte_array() {
let prng = Aes128Ctr64::from_seed(Aes128Ctr64Seed::default());
let bytes: [u8; 128] = prng.byte_array();
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_shuffle() {
let prng = Aes128Ctr64::from_seed(Aes128Ctr64Seed::default());
Expand Down
14 changes: 13 additions & 1 deletion tests/aes256_ctr128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ test_primitive_integer!(test_prng_u8, u8);
test_primitive_integer!(test_prng_u16, u16);
test_primitive_integer!(test_prng_u32, u32);
test_primitive_integer!(test_prng_u64, u64);
test_primitive_integer!(test_prng_u128, u128);
test_primitive_integer!(test_prng_usize, usize);
test_primitive_integer!(test_prng_i8, i8);
test_primitive_integer!(test_prng_i16, i16);
test_primitive_integer!(test_prng_i32, i32);
test_primitive_integer!(test_prng_i64, i64);
test_primitive_integer!(test_prng_i128, i128);
test_primitive_integer!(test_prng_isize, isize);

#[test]
Expand Down Expand Up @@ -121,14 +123,24 @@ fn test_prng_f64() {
#[test]
fn test_prng_fill_bytes() {
let prng = Aes256Ctr128::from_seed(Aes256Ctr128Seed::default());
let mut bytes = [0u8; 16];
let mut bytes = [0u8; 128];
prng.fill_bytes(&mut bytes);
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_byte_array() {
let prng = Aes256Ctr128::from_seed(Aes256Ctr128Seed::default());
let bytes: [u8; 128] = prng.byte_array();
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_shuffle() {
let prng = Aes256Ctr128::from_seed(Aes256Ctr128Seed::default());
Expand Down
14 changes: 13 additions & 1 deletion tests/aes256_ctr64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ test_primitive_integer!(test_prng_u8, u8);
test_primitive_integer!(test_prng_u16, u16);
test_primitive_integer!(test_prng_u32, u32);
test_primitive_integer!(test_prng_u64, u64);
test_primitive_integer!(test_prng_u128, u128);
test_primitive_integer!(test_prng_usize, usize);
test_primitive_integer!(test_prng_i8, i8);
test_primitive_integer!(test_prng_i16, i16);
test_primitive_integer!(test_prng_i32, i32);
test_primitive_integer!(test_prng_i64, i64);
test_primitive_integer!(test_prng_i128, i128);
test_primitive_integer!(test_prng_isize, isize);

#[test]
Expand Down Expand Up @@ -121,14 +123,24 @@ fn test_prng_f64() {
#[test]
fn test_prng_fill_bytes() {
let prng = Aes256Ctr64::from_seed(Aes256Ctr64Seed::default());
let mut bytes = [0u8; 16];
let mut bytes = [0u8; 128];
prng.fill_bytes(&mut bytes);
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_byte_array() {
let prng = Aes256Ctr64::from_seed(Aes256Ctr64Seed::default());
let bytes: [u8; 128] = prng.byte_array();
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_shuffle() {
let prng = Aes256Ctr64::from_seed(Aes256Ctr64Seed::default());
Expand Down
14 changes: 13 additions & 1 deletion tests/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ mod test {
test_primitive_integer!(test_prng_u16, rand_u16);
test_primitive_integer!(test_prng_u32, rand_u32);
test_primitive_integer!(test_prng_u64, rand_u64);
test_primitive_integer!(test_prng_u128, rand_u128);
test_primitive_integer!(test_prng_usize, rand_usize);
test_primitive_integer!(test_prng_i8, rand_i8);
test_primitive_integer!(test_prng_i16, rand_i16);
test_primitive_integer!(test_prng_i32, rand_i32);
test_primitive_integer!(test_prng_i64, rand_i64);
test_primitive_integer!(test_prng_i128, rand_i128);
test_primitive_integer!(test_prng_isize, rand_isize);

#[test]
Expand Down Expand Up @@ -123,14 +125,24 @@ mod test {
#[test]
fn test_prng_fill_bytes() {
rand_seed(Seed::default());
let mut bytes = [0u8; 16];
let mut bytes = [0u8; 128];
rand_fill_bytes(&mut bytes);
assert!(
!bytes.iter().all(|&x| x == 0),
"Filled bytes should not be all zeros"
);
}

#[test]
fn test_prng_byte_array() {
rand_seed(Seed::default());
let bytes: [u8; 128] = rand_byte_array();
assert!(
!bytes.iter().all(|&x| x == 0),
"Bytes array should not be all zeros"
);
}

#[test]
fn test_prng_shuffle() {
rand_seed(Seed::default());
Expand Down

0 comments on commit ef33f67

Please sign in to comment.