Skip to content

Commit 10432e1

Browse files
committed
Merge pull request #362 from mernen/digest-copy-clone
Implement Copy and Clone for all Digest impls
2 parents 732b988 + 2b37093 commit 10432e1

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/cryptoutil.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,14 @@ impl FixedBuffer64 {
461461
impl_fixed_buffer!(FixedBuffer64, 64);
462462

463463
/// A fixed size buffer of 128 bytes useful for cryptographic operations.
464+
#[derive(Copy)]
464465
pub struct FixedBuffer128 {
465466
buffer: [u8; 128],
466467
buffer_idx: usize,
467468
}
468469

470+
impl Clone for FixedBuffer128 { fn clone(&self) -> FixedBuffer128 { *self } }
471+
469472
impl FixedBuffer128 {
470473
/// Create a new buffer
471474
pub fn new() -> FixedBuffer128 {

src/md5.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use step_by::RangeExt;
1414

1515

1616
// A structure that represents that state of a digest computation for the MD5 digest function
17+
#[derive(Clone, Copy)]
1718
struct Md5State {
1819
s0: u32,
1920
s1: u32,
@@ -151,6 +152,7 @@ static C4: [u32; 16] = [
151152

152153

153154
/// The MD5 Digest algorithm
155+
#[derive(Clone, Copy)]
154156
pub struct Md5 {
155157
length_bytes: u64,
156158
buffer: FixedBuffer64,

src/sha2.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ pub fn sha512_digest_block(state: &mut [u64; 8], block: &[u8/*; 128*/]) {
644644

645645
// A structure that represents that state of a digest computation for the SHA-2 512 family
646646
// of digest functions
647+
#[derive(Copy, Clone)]
647648
struct Engine512State {
648649
h: [u64; 8]
649650
}
@@ -704,6 +705,7 @@ pub const K64X2: [u64x2; 40] = [
704705

705706
// A structure that keeps track of the state of the Sha-512 operation and contains the logic
706707
// necessary to perform the final calculations.
708+
#[derive(Copy, Clone)]
707709
struct Engine512 {
708710
length_bits: (u64, u64),
709711
buffer: FixedBuffer128,
@@ -757,6 +759,7 @@ impl Engine512 {
757759

758760

759761
/// The SHA-512 hash algorithm with the SHA-512 initial hash value.
762+
#[derive(Copy, Clone)]
760763
pub struct Sha512 {
761764
engine: Engine512
762765
}
@@ -812,6 +815,7 @@ static H512: [u64; STATE_LEN] = [
812815

813816

814817
/// The SHA-512 hash algorithm with the SHA-384 initial hash value. The result is truncated to 384 bits.
818+
#[derive(Copy, Clone)]
815819
pub struct Sha384 {
816820
engine: Engine512
817821
}
@@ -865,6 +869,7 @@ static H384: [u64; STATE_LEN] = [
865869

866870

867871
/// The SHA-512 hash algorithm with the SHA-512/256 initial hash value. The result is truncated to 256 bits.
872+
#[derive(Clone, Copy)]
868873
pub struct Sha512Trunc256 {
869874
engine: Engine512
870875
}
@@ -916,6 +921,7 @@ static H512_TRUNC_256: [u64; STATE_LEN] = [
916921

917922

918923
/// The SHA-512 hash algorithm with the SHA-512/224 initial hash value. The result is truncated to 224 bits.
924+
#[derive(Clone, Copy)]
919925
pub struct Sha512Trunc224 {
920926
engine: Engine512
921927
}

src/whirlpool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::mem::uninitialized;
3939
use cryptoutil::{write_u64_be, FixedBuffer64, FixedBuffer};
4040
use digest::Digest;
4141

42+
#[derive(Clone, Copy)]
4243
pub struct Whirlpool {
4344
bit_length: [u8; 32],
4445
buffer: FixedBuffer64,

0 commit comments

Comments
 (0)