From 41c0945bea6fe08d30f2706012ee6107fe4105a8 Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 26 Jan 2021 07:55:28 +0000 Subject: [PATCH] types are now Ord --- Cargo.toml | 4 ++-- src/aes.rs | 2 +- src/rsa/sign.rs | 42 +++++++++--------------------------------- src/sha256.rs | 2 +- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 538dada..7c88fba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cryptohelpers" -version = "1.7.1" +version = "1.7.2" license= "MIT" description = "Collection of helpers and simplifying functions for cryptography things" authors = ["Avril "] @@ -9,7 +9,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -openssl = {version = "0.10", optional = true} +openssl = { version = "0.10.32", optional = true } pbkdf2 = {version = "0.5", optional = true } sha2 = {version = "0.9", optional = true } hmac = {version = "0.9", optional = true } diff --git a/src/aes.rs b/src/aes.rs index 97a8f9d..cb9538d 100644 --- a/src/aes.rs +++ b/src/aes.rs @@ -29,7 +29,7 @@ use consts::BUFFER_SIZE; const BLOCKSIZE: usize = 16; /// A key and IV for the AES algorithm -#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)] +#[derive(Debug, PartialEq, Eq, Clone, Hash, Default, PartialOrd, Ord)] #[cfg_attr(feature="serialise", derive(Serialize,Deserialize))] #[repr(align(1))] pub struct AesKey { diff --git a/src/rsa/sign.rs b/src/rsa/sign.rs index 76b4710..fb3246a 100644 --- a/src/rsa/sign.rs +++ b/src/rsa/sign.rs @@ -37,9 +37,17 @@ use consts::RSA_SIG_SIZE as SIZE; use consts::BUFFER_SIZE; /// Represents an RSA signature -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct Signature([u8; SIZE]); +impl Default for Signature +{ + #[inline] + fn default() -> Self + { + Self([0u8; SIZE]) + } +} #[cfg(feature="serialise")] const _: () = { use serde::{ @@ -309,38 +317,6 @@ impl AsMut<[u8]> for Signature } } -impl Default for Signature -{ - #[inline] - fn default() -> Self - { - Self([0u8; SIZE]) - } -} - -impl Eq for Signature{} -impl PartialEq for Signature -{ - #[inline] fn eq(&self, other: &Self) -> bool - { - &self.0[..] == &other.0[..] - } -} - -impl Hash for Signature { - fn hash(&self, state: &mut H) { - self.0[..].hash(state) - } -} - -impl Debug for Signature -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result - { - write!(f, "Signature ({:?})", &self.0[..]) - } -} - impl Display for Signature { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result diff --git a/src/sha256.rs b/src/sha256.rs index 2c9513f..c3fd0c0 100644 --- a/src/sha256.rs +++ b/src/sha256.rs @@ -18,7 +18,7 @@ use tokio::{ pub const SIZE: usize = consts::SHA256_SIZE; /// Represents a SHA256 hash -#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[repr(transparent)] #[cfg_attr(feature="serialise", derive(Serialize,Deserialize))] pub struct Sha256Hash