pub mod cert;
pub mod comm;
pub mod mlsjoin;
pub mod package;
pub mod session;
mod codec;
#[cfg(test)]
mod tests;
#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum LinkError {
#[error("malformed: {0}")]
Malformed(String),
#[error("expired: {0}")]
Expired(String),
#[error("mismatch: {0}")]
Mismatch(String),
#[error("replay: {0}")]
Replay(String),
#[error("state: {0}")]
State(String),
#[error("crypto: {0}")]
Crypto(String),
}
pub type LR<T> = Result<T, LinkError>;
impl From<crate::primitives::PrimitiveError> for LinkError {
fn from(e: crate::primitives::PrimitiveError) -> Self {
LinkError::Crypto(e.to_string())
}
}
pub(crate) const DOMAIN: &[u8] = b"umbera-link-v1";
pub(crate) fn ct_eq(a: &[u8], b: &[u8]) -> bool {
if a.len() != b.len() {
return false;
}
let mut d = 0u8;
for (x, y) in a.iter().zip(b) {
d |= x ^ y;
}
std::hint::black_box(d) == 0
}
pub(crate) fn sha256(parts: &[&[u8]]) -> [u8; 32] {
use sha2::{Digest, Sha256};
let mut h = Sha256::new();
for p in parts {
h.update(p);
}
h.finalize().into()
}
pub(crate) fn sha256_framed(parts: &[&[u8]]) -> [u8; 32] {
use sha2::{Digest, Sha256};
let mut h = Sha256::new();
for p in parts {
h.update((p.len() as u32).to_be_bytes());
h.update(p);
}
h.finalize().into()
}