authority.rs 1.28 KB
Newer Older
1
2
3
4
5
//! Information about directory authorities
//!
//! From a client's point of view, an authority's role is to to sign the
//! consensus directory.

6
use serde::Deserialize;
7
8
9
10
use tor_llcrypto::pk::rsa::RSAIdentity;
use tor_netdoc::doc::authcert::{AuthCert, AuthCertKeyIds};

/// A single authority that signs a consensus directory.
11
#[derive(Deserialize, Debug, Clone)]
12
13
14
15
16
17
18
19
20
21
22
23
24
25
pub struct Authority {
    /// A memorable nickname for this authority.
    name: String,
    /// A SHA1 digest of the DER-encoded long-term v3 RSA identity key for
    /// this authority.
    // TODO: It would be lovely to use a better hash for these identities.
    v3ident: RSAIdentity,
}

impl Authority {
    /// Construct information about a new authority.
    pub fn new(name: String, v3ident: RSAIdentity) -> Self {
        Authority { name, v3ident }
    }
26
27
28
29
    /// Return the v3 identity key of this certificate.
    pub fn v3ident(&self) -> &RSAIdentity {
        &self.v3ident
    }
30
31
32
33
    /// Return true if this authority matches a given certificate.
    pub fn matches_cert(&self, cert: &AuthCert) -> bool {
        &self.v3ident == cert.id_fingerprint()
    }
34

35
36
37
38
39
    /// Return true if this authority matches a given key ID.
    pub fn matches_keyid(&self, id: &AuthCertKeyIds) -> bool {
        self.v3ident == id.id_fingerprint
    }
}