ps-hkey 0.1.0-34

This crate defines the hashkey format and provides methods for resolving them
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use ps_base64::base64;

use crate::{methods::compact::compact_dhash, AsyncStore, Hkey};

impl Hkey {
    pub async fn compact_async<S: AsyncStore>(&self, store: &S) -> Result<Vec<u8>, S::Error> {
        match self.shrink_async(store).await? {
            Self::Raw(value) => Ok(value.to_vec()),
            Self::Base64(value) => Ok(base64::decode(value.as_bytes())),
            Self::Direct(hash) => Ok(hash.compact().to_vec()),
            Self::Encrypted(hash, key) => Ok(compact_dhash(&hash, &key, 0)),
            Self::ListRef(hash, key) => Ok(compact_dhash(&hash, &key, 1)),
            Self::LongHkey(lhkey) => Ok(compact_dhash(lhkey.hash_ref(), lhkey.key_ref(), 1)),
            hkey => hkey.shrink_async(store).await?.compact_async(store).await,
        }
    }
}