Browse Source

Use #[derive] for Clone and Debug

Before the conversion to SIMD-like vectors, this was not possible
because the array had more than 32 elements, and these traits are only
implemented for arrays of up to 32 elements.

After the conversion, the array has only 2 elements, so deriving these
traits is possible and simplifies the code.
pull/2/head 0.2.10
Cesar Eduardo Barros 9 years ago
parent
commit
8d895f7986
  1. 2
      Cargo.toml
  2. 14
      src/blake2.rs

2
Cargo.toml

@ -1,6 +1,6 @@
[package]
name = "blake2-rfc"
version = "0.2.9"
version = "0.2.10"
authors = ["Cesar Eduardo Barros <cesarb@cesarb.eti.br>"]
description = "A pure Rust implementation of BLAKE2 based on the draft RFC."
repository = "https://github.com/cesarb/blake2-rfc"

14
src/blake2.rs

@ -42,7 +42,6 @@ macro_rules! blake2_impl {
($state:ident, $result:ident, $func:ident, $word:ident, $vec:ident,
$bytes:expr, $R1:expr, $R2:expr, $R3:expr, $R4:expr, $IV:expr) => {
use std::cmp;
use std::fmt::{self, Debug};
use std::io;
use $crate::as_bytes::AsBytes;
@ -55,7 +54,7 @@ macro_rules! blake2_impl {
/// This container uses a constant-time comparison for equality.
/// If a constant-time comparison is not necessary, the hash
/// result can be extracted with the `as_bytes` method.
#[derive(Copy)]
#[derive(Clone, Copy, Debug)]
pub struct $result {
h: [$vec; 2],
nn: usize,
@ -79,17 +78,6 @@ macro_rules! blake2_impl {
fn as_ref(&self) -> &[u8] { self.as_bytes() }
}
impl Clone for $result {
#[inline]
fn clone(&self) -> Self { *self }
}
impl Debug for $result {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(self.as_bytes(), f)
}
}
impl Eq for $result { }
impl PartialEq for $result {

Loading…
Cancel
Save