postgres session storage backend

This commit is contained in:
Igor Katson 2024-08-15 14:18:55 +01:00
parent f22814c77b
commit 2871c358e3
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
8 changed files with 99 additions and 48 deletions

View file

@ -14,6 +14,15 @@ impl<const N: usize> Id<N> {
hex::encode(self.0)
}
pub fn from_bytes(b: &[u8]) -> anyhow::Result<Self> {
let mut v = [0u8; N];
if b.len() != N {
anyhow::bail!("buffer length must be {}, but it's {}", N, b.len());
}
v.copy_from_slice(b);
Ok(Id(v))
}
pub fn distance(&self, other: &Id<N>) -> Id<N> {
let mut xor = [0u8; N];
for (idx, (s, o)) in self