mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 01:00:12 +00:00
chore: merge avatars service into monorepo
This commit is contained in:
parent
f427d4d727
commit
17f5561293
27 changed files with 1925 additions and 111 deletions
21
services/avatars/src/hash.rs
Normal file
21
services/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