signal_auditor/
lib.rs

1//! An implementation of the Third-Party Auditor role for the
2//! [Signal Key Transparency Log.](https://github.com/signalapp/key-transparency-server)
3
4pub mod auditor;
5pub mod log;
6pub mod prefix;
7pub mod transparency;
8/// Protocol buffer definitions for transparency log network messages.
9pub mod proto {
10    pub mod transparency {
11        include!(concat!(env!("OUT_DIR"), "/transparency.rs"));
12    }
13    pub mod kt {
14        include!(concat!(env!("OUT_DIR"), "/kt.rs"));
15    }
16}
17
18type Hash = [u8; 32];
19/// Convert a vector of bytes into a hash.
20///
21/// # Errors
22///
23/// Returns an error if the input is not 32 bytes.
24fn try_into_hash(x: Vec<u8>) -> Result<Hash, anyhow::Error> {
25    let arr: [u8; 32] = x.try_into().map_err(|_| anyhow::anyhow!("Invalid hash"))?;
26    Ok(arr)
27}
28
29type Index = [u8; 32];
30type Seed = [u8; 16];
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use hex_literal::hex;
36    use proto::transparency::AuditorProof;
37    use proto::transparency::AuditorUpdate;
38    use proto::transparency::auditor_proof::{NewTree, Proof};
39    use transparency::TransparencyLog;
40
41    //real=true, index=72304a54df58d7d2673f7f99fe1689ca939eebc55741f3d1335904cb9c8564e4, seed=c3009d216ad487428a6f904ede447bc9, commitment=5f799a1d6d34dffacbec4d47c4f200a6be09de9b6d444ad27e87ba0beaad3607, proof=newTree{}
42    // logRoot = 1e6fdd7508a05b5ba2661f7eec7e8df0a0ee9a277ca5b345f17fbe8e6aa8e9d1
43    #[test]
44    fn test_initialize() {
45        let mut log = TransparencyLog::new();
46        let index =
47            hex!("72304a54df58d7d2673f7f99fe1689ca939eebc55741f3d1335904cb9c8564e4").to_vec();
48        let seed = hex!("c3009d216ad487428a6f904ede447bc9").to_vec();
49        let commitment =
50            hex!("5f799a1d6d34dffacbec4d47c4f200a6be09de9b6d444ad27e87ba0beaad3607").into();
51        let proof = Some(AuditorProof {
52            proof: Some(Proof::NewTree(NewTree {})),
53        });
54
55        let expected_log_root =
56            hex!("1e6fdd7508a05b5ba2661f7eec7e8df0a0ee9a277ca5b345f17fbe8e6aa8e9d1");
57
58        let update = AuditorUpdate {
59            real: true,
60            index,
61            seed,
62            commitment,
63            proof,
64        };
65
66        log.apply_update(update).unwrap();
67
68        assert!(log.is_initialized());
69        assert_eq!(log.log_root().unwrap(), expected_log_root);
70    }
71}