fix: resolve trait implementation errors and fix hasher move in finalize
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::io;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct DigestEngineSha256 {
|
||||
hasher: Sha256,
|
||||
}
|
||||
@@ -10,10 +10,28 @@ impl DigestEngineSha256 {
|
||||
pub fn new() -> DigestEngineSha256 {
|
||||
DigestEngineSha256 { hasher: Sha256::new() }
|
||||
}
|
||||
|
||||
// Manual implementation of PartialEq
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.hasher.result().as_slice() == other.hasher.result().as_slice()
|
||||
}
|
||||
|
||||
// Manual implementation of Eq
|
||||
fn is_eq(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
use crate::digest_engine::DigestEngine;
|
||||
|
||||
impl PartialEq for DigestEngineSha256 {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for DigestEngineSha256 {}
|
||||
|
||||
impl DigestEngine for DigestEngineSha256 {
|
||||
fn create(&self) -> Box<dyn DigestEngine> {
|
||||
Box::new(Self::new())
|
||||
@@ -25,7 +43,7 @@ impl DigestEngine for DigestEngineSha256 {
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> io::Result<String> {
|
||||
let result = self.hasher.finalize();
|
||||
let result = self.hasher.clone().finalize();
|
||||
Ok(format!("{:x}", result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user