scsys_crypto/
lib.rs

1/*
2    Appellation: scsys-crypto <library>
3    Contrib: FL03 <jo3mccain@icloud.com>
4    Description: ... summary ...
5*/
6#[doc(inline)]
7pub use self::{hash::*, keys::*, primitives::*, specs::*};
8
9pub(crate) mod hash;
10pub(crate) mod keys;
11pub(crate) mod primitives;
12pub(crate) mod utils;
13
14pub(crate) mod specs {
15    use crate::hash::{hasher, H256};
16
17    pub trait Hashable
18    where
19        Self: std::fmt::Display,
20    {
21        fn hash(&self) -> H256;
22    }
23
24    pub trait HashableExt: Hashable {
25        fn hasher(&self, deg: Option<usize>) -> H256 {
26            let s: H256 = hasher(&self).into();
27
28            let mut res: H256 = s;
29            for _ in 0..deg.unwrap_or(1) {
30                res = hasher(&res.clone()).into()
31            }
32            res
33        }
34    }
35
36    pub trait ArrayLike<T, E: std::error::Error> {
37        fn flush(&mut self) -> Result<(), E>;
38        fn get(&self, index: usize) -> Result<Option<T>, E>;
39        fn is_empty(&self) -> Result<bool, E>;
40        fn len(&self) -> Result<usize, E>;
41        fn position(&self, item: &T) -> Result<Option<usize>, E>;
42        fn push(&mut self, item: T) -> Result<usize, E>;
43    }
44
45    // pub trait ArrayLikeExt {
46    //     type Value;
47    //     fn truncate(&mut self, _len: usize) -> Result<(), MerkleMountainRangeError>;
48    //     fn shift(&mut self, n: usize) -> Result<(), MerkleMountainRangeError>;
49    //     fn push_front(
50    //         &mut self,
51    //         item: Self::Value
52    //     ) -> Result<(), MerkleMountainRangeError>;
53    //     fn for_each<F>(&self, f: F) -> Result<(), MerkleMountainRangeError>
54    //     where
55    //         F: FnMut(Result<Self::Value, MerkleMountainRangeError>);
56    // }
57}