use darkbio_crypto::cbor::Cbor;
use darkbio_crypto::{xdsa, xhpke};
#[derive(Cbor)]
#[cbor(array)]
pub(crate) struct HostHello {
pub host_signer: xdsa::PublicKey, pub host_crypto: xhpke::PublicKey, }
#[derive(Cbor)]
#[cbor(array)]
pub(crate) struct ArkHello {
pub ark_attest: Vec<u8>, pub ark_crypto: xhpke::PublicKey, pub a2h_encap: Vec<u8>, }
#[derive(Cbor)]
#[cbor(array)]
pub(crate) struct ArkHelloAuth {
pub host_signer: xdsa::PublicKey, pub host_crypto: xhpke::PublicKey, }
#[derive(Cbor)]
#[cbor(array)]
pub(crate) struct HostAck {
pub h2a_encap: Vec<u8>, }
#[derive(Cbor)]
#[cbor(array)]
pub(crate) struct HostAckAuth {
pub ark_signer: xdsa::PublicKey, pub ark_crypto: xhpke::PublicKey, }
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use super::*;
use darkbio_crypto::cbor;
#[test]
fn test_message_vectors() {
fn signer(seed: u8) -> xdsa::PublicKey {
xdsa::SecretKey::from_bytes(&[seed; xdsa::SECRET_KEY_SIZE]).public_key()
}
fn crypto(seed: u8) -> xhpke::PublicKey {
xhpke::SecretKey::from_bytes(&[seed; xhpke::SECRET_KEY_SIZE]).public_key()
}
fn filler(len: usize) -> Vec<u8> {
(0..len).map(|i| i as u8).collect()
}
struct TestCase {
encoded: Vec<u8>,
vector: &'static [u8],
}
let tests = [
TestCase {
encoded: cbor::encode(&HostHello {
host_signer: signer(1),
host_crypto: crypto(2),
})
.unwrap(),
vector: include_bytes!("testdata/handshake/host_hello.cbor"),
},
TestCase {
encoded: cbor::encode(&ArkHello {
ark_attest: filler(300),
ark_crypto: crypto(3),
a2h_encap: filler(xhpke::ENCAP_KEY_SIZE),
})
.unwrap(),
vector: include_bytes!("testdata/handshake/ark_hello.cbor"),
},
TestCase {
encoded: cbor::encode(&ArkHelloAuth {
host_signer: signer(4),
host_crypto: crypto(5),
})
.unwrap(),
vector: include_bytes!("testdata/handshake/ark_hello_auth.cbor"),
},
TestCase {
encoded: cbor::encode(&HostAck {
h2a_encap: filler(xhpke::ENCAP_KEY_SIZE),
})
.unwrap(),
vector: include_bytes!("testdata/handshake/host_ack.cbor"),
},
TestCase {
encoded: cbor::encode(&HostAckAuth {
ark_signer: signer(6),
ark_crypto: crypto(3),
})
.unwrap(),
vector: include_bytes!("testdata/handshake/host_ack_auth.cbor"),
},
];
for (i, tt) in tests.into_iter().enumerate() {
assert_eq!(tt.encoded, tt.vector, "test {i}");
}
}
}