Skip to main content

tor_netdoc/doc/netstatus/rs/
md.rs

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
7use super::*;
8
9// Import `each_variety.rs`, appropriately variegated
10ns_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::*`.
14pub(crate) use crate::doc::microdesc::{DOC_DIGEST_LEN, MdDigest as DocDigest};
15
16/// The flavor
17const FLAVOR: ConsensusFlavor = ConsensusFlavor::Microdesc;
18
19impl RouterStatus {
20    /// Return the expected microdescriptor digest for this routerstatus
21    pub fn md_digest(&self) -> &DocDigest {
22        self.doc_digest()
23    }
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`.
31pub(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    #[cfg(feature = "incomplete")] // untested
39    #[expect(dead_code)] // will be used when we encode a whole routerstatus
40    #[allow(clippy::unnecessary_wraps)]
41    pub(crate) fn write_item_value_onto(
42        digest: &FixedB64<DOC_DIGEST_LEN>,
43        out: ItemEncoder,
44    ) -> Result<(), Bug> {
45        out.arg(digest);
46        Ok(())
47    }
48
49    /// Parse the whole `m` item value
50    pub(crate) fn from_unparsed(mut item: UnparsedItem) -> Result<FixedB64<DOC_DIGEST_LEN>, EP> {
51        item.check_no_object()?;
52        FixedB64::from_args(item.args_mut()).map_err(item.args().error_handler("doc_digest"))
53    }
54}