1
//! Implementation for the style of router descriptors 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
65752073
    pub fn md_digest(&self) -> &DocDigest {
22
65752073
        self.doc_digest()
23
65752073
    }
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
#[cfg(feature = "parse2")]
32
pub(crate) mod doc_digest_parse2_real_item {
33
    use super::*;
34
    use crate::parse2::ErrorProblem as EP;
35
    use crate::parse2::UnparsedItem;
36
    use std::result::Result;
37

            
38
    /// Parse the whole `m` item
39
12
    pub(crate) fn from_unparsed(mut item: UnparsedItem<'_>) -> Result<DocDigest, EP> {
40
12
        item.check_no_object()?;
41
12
        doc_digest_parse2_real::from_args(item.args_mut())
42
12
            .map_err(item.args().error_handler("doc_digest"))
43
12
    }
44
}