rho-coding-agent 3.10.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Random secrets and comparing them: the bearer tokens, channel tokens
//! and per-run tokens rho hands out and checks.

use rand::{rand_core::UnwrapErr, rngs::SysRng, Rng};

/// `BYTES` bytes from the OS's generator, as lowercase hex.
pub(crate) fn random_hex<const BYTES: usize>() -> String {
    let mut bytes = [0_u8; BYTES];
    UnwrapErr(SysRng).fill_bytes(&mut bytes);
    hex::encode(bytes)
}

/// Whether `left` and `right` are equal, compared in time that depends on
/// their lengths only, so the time taken does not tell how much of a
/// presented secret matched.
pub(crate) fn constant_time_eq(left: &[u8], right: &[u8]) -> bool {
    left.len() == right.len()
        && left
            .iter()
            .zip(right)
            .fold(0_u8, |difference, (left, right)| {
                difference | (left ^ right)
            })
            == 0
}