1
//! Implementation for the style of router status entries used in
2
//! microdesc consensus documents.
3
//
4
// Read this file in conjunction with `each_variety.rs`.
5
// See "module scope" ns_variety_definition_macros.rs.
6

            
7
use super::*;
8

            
9
// Import `each_variety.rs`, appropriately variegated
10
ns_do_variety_md! {}
11

            
12
// We bind some variety-agnostic names for the benefit of `each_variety.rs`,
13
// which reimports the contents of this module with `use super::*`.
14
pub(crate) use crate::doc::microdesc::{DOC_DIGEST_LEN, MdDigest as DocDigest};
15

            
16
/// The flavor
17
const FLAVOR: ConsensusFlavor = ConsensusFlavor::Microdesc;
18

            
19
impl RouterStatus {
20
    /// Return the expected microdescriptor digest for this routerstatus
21
71123882
    pub fn md_digest(&self) -> &DocDigest {
22
71123882
        self.doc_digest()
23
71123882
    }
24
}
25

            
26
/// Netdoc format helper module for referenced doc digest field in `m` (where it's an item)
27
///
28
/// See `doc_digest_parse2_real` in `rs/each_variety.rs`.
29
/// This is in `md.rs` because it's needed only for md consensuses.
30
/// Elsewhere, the value is in the `r` item, so is merely `ItemArgumentParseable`.
31
pub(crate) mod doc_digest_item_m {
32
    use super::*;
33
    use crate::parse2::ErrorProblem as EP;
34
    use crate::parse2::UnparsedItem;
35
    use std::result::Result;
36

            
37
    /// Output the whole `m` item value
38
    #[allow(clippy::unnecessary_wraps)]
39
24
    pub(crate) fn write_item_value_onto(
40
24
        digest: &FixedB64<DOC_DIGEST_LEN>,
41
24
        out: ItemEncoder,
42
24
    ) -> Result<(), Bug> {
43
24
        out.arg(digest);
44
24
        Ok(())
45
24
    }
46

            
47
    /// Parse the whole `m` item value
48
38
    pub(crate) fn from_unparsed(mut item: UnparsedItem) -> Result<FixedB64<DOC_DIGEST_LEN>, EP> {
49
38
        item.check_no_object()?;
50
38
        FixedB64::from_args(item.args_mut()).map_err(item.args().error_handler("doc_digest"))
51
38
    }
52
}