1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use digest::{generic_array::GenericArray, Digest};
use sha1::Sha1;
use std::{
fmt::{self, Debug},
ops::Deref,
};
pub struct SourceKey<A: Digest = Sha1>(GenericArray<u8, A::OutputSize>);
impl<A: Digest> SourceKey<A> {
#[inline]
pub fn new(array: impl Into<GenericArray<u8, A::OutputSize>>) -> Self {
Self::from(array.into())
}
}
impl<A: Digest> Deref for SourceKey<A> {
type Target = GenericArray<u8, A::OutputSize>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<A: Digest> From<GenericArray<u8, A::OutputSize>> for SourceKey<A> {
#[inline]
fn from(array: GenericArray<u8, A::OutputSize>) -> Self {
Self(array)
}
}
impl<A: Digest> Debug for SourceKey<A> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("SourceKey").field(&self.0).finish()
}
}
impl<A: Digest> Clone for SourceKey<A> {
#[inline]
fn clone(&self) -> Self {
Self(self.0.clone())
}
}