evidence 0.1.0

Type-level tags for cryptographic primitives
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Blake3 hash implementation.

use super::DigestPrimitive;
use hybrid_array::{Array, typenum::U32};

/// Blake3 hash primitive (32 bytes).
#[derive(Debug, Clone, Copy)]
pub enum Blake3 {}

impl DigestPrimitive for Blake3 {
    type Size = U32;

    #[allow(clippy::expect_used)] // output size is type-level guaranteed
    fn hash(data: &[u8]) -> Array<u8, Self::Size> {
        let result = blake3::hash(data);
        Array::try_from(result.as_bytes().as_slice()).expect("blake3 output is always 32 bytes")
    }
}