azure_storage_blobs/options/
hash.rs

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
use azure_core::{
    base64,
    headers::{self, Header, CONTENT_MD5},
};
use azure_storage::headers::CONTENT_CRC64;

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
pub enum Hash {
    MD5([u8; 16]),
    CRC64(u64),
}

impl Header for Hash {
    fn name(&self) -> headers::HeaderName {
        match self {
            Hash::MD5(_) => CONTENT_MD5,
            Hash::CRC64(_) => CONTENT_CRC64,
        }
    }

    fn value(&self) -> headers::HeaderValue {
        match self {
            Hash::MD5(md5) => base64::encode(md5),
            Hash::CRC64(crc64) => format!("{crc64}"),
        }
        .into()
    }
}

impl From<[u8; 16]> for Hash {
    fn from(md5: [u8; 16]) -> Self {
        Hash::MD5(md5)
    }
}

#[cfg(feature = "md5")]
impl From<md5::Digest> for Hash {
    fn from(md5: md5::Digest) -> Self {
        Hash::MD5(md5.0)
    }
}