mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 08:40:11 +00:00
chore: reorganize rust crates
This commit is contained in:
parent
357122a892
commit
16ce67e02c
58 changed files with 6 additions and 13 deletions
21
crates/avatars/src/hash.rs
Normal file
21
crates/avatars/src/hash.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Hash([u8; 32]);
|
||||
|
||||
impl Hash {
|
||||
pub fn sha256(data: &[u8]) -> Hash {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(data);
|
||||
Hash(hasher.finalize().into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Hash {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let encoding = data_encoding::BASE32_NOPAD;
|
||||
write!(f, "{}", encoding.encode(&self.0[..16]).to_lowercase())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue