summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-22 14:55:28 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-23 22:00:56 +0800
commit7aa4a2704299a8fa4872f90836dac864dcf24222 (patch)
tree92fee861fd4463f7c928f90541322e7541988370
parent9b2dcd8bae4021d692ba5f44194d2020d736012b (diff)
chore(hashchain): rename hash
-rw-r--r--src/hash_chain.rs21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/hash_chain.rs b/src/hash_chain.rs
index 4a37c67..9beb60b 100644
--- a/src/hash_chain.rs
+++ b/src/hash_chain.rs
@@ -35,7 +35,7 @@ impl<T: Encode> HashChain<T> {
})
.unwrap_or_default();
self.data
- .push((Self::with_hash((&prev_hash, &data)), data));
+ .push((Self::hash_item((&prev_hash, &data)), data));
}
// TODO: make try_last that does same as this but returns Err() if it's not the
@@ -47,7 +47,7 @@ impl<T: Encode> HashChain<T> {
.position(|x| x.0 == *base_hash)
.unwrap();
self.data
- .insert(pos + 1, (Self::with_hash((base_hash, &data)), data));
+ .insert(pos + 1, (Self::hash_item((base_hash, &data)), data));
// everything after that hash is invalidated
self.rehash(&base_hash);
@@ -63,7 +63,7 @@ impl<T: Encode> HashChain<T> {
.iter()
.enumerate()
.all(|(prev_hash, (pred_prev_hash, _))| {
- let prev_hash = Self::with_hash({
+ let prev_hash = Self::hash_item({
let prev_hash = &self.data[prev_hash - 1];
(&prev_hash.0, &prev_hash.1)
});
@@ -82,7 +82,7 @@ impl<T: Encode> HashChain<T> {
.data
.len())
.map(|i| {
- Self::with_hash({
+ Self::hash_item({
let prev_hash = &self.data[i - 1];
(&prev_hash.0, &prev_hash.1)
})
@@ -100,24 +100,13 @@ impl<T: Encode> HashChain<T> {
});
}
- fn with_hash(data: (&Vec<u8>, &T)) -> Vec<u8> {
+ fn hash_item(data: (&Vec<u8>, &T)) -> Vec<u8> {
let mut hasher = Sha256::new();
hasher.update(bincode::encode_to_vec(data, bincode::config::standard()).unwrap());
hasher
.finalize()
.to_vec()
}
-
- fn hash_last(&self) -> Vec<u8> {
- Self::with_hash({
- let last = self
- .data
- .iter()
- .last()
- .unwrap();
- (&last.0, &last.1)
- })
- }
}
impl<T: Encode> Deref for HashChain<T> {