1
1
//! Parse and represent directory objects used in Tor.
2
//!
3
//! # Overview
4
//!
5
//! Tor has several "directory objects" that it uses to convey
6
//! information about relays on the network. They are documented in
7
//! dir-spec.txt.
8
//!
9
//! This crate has common code to parse and validate these documents.
10
//! Currently, it can handle the metaformat, along with certain parts
11
//! of the router descriptor type. We will eventually need to handle
12
//! more types.
13
//!
14
//! This crate is part of
15
//! [Arti](https://gitlab.torproject.org/tpo/core/arti/), a project to
16
//! implement [Tor](https://www.torproject.org/) in Rust.
17
//!
18
//! ## Design notes
19
//!
20
//! The crate is derived into three main parts.  In the (private) `parse`
21
//! module, we have the generic code that we use to parse different
22
//! kinds of network documents.  In the [`types`] module we have
23
//! implementations for parsing specific data structures that are used
24
//! inside directory documents.  Finally, the [`doc`] module defines
25
//! the parsers for the documents themselves.
26
//!
27
//! # Features
28
//!
29
//! `build_docs`: enable code to construct the objects representing different
30
//! network documents.
31
//!
32
//! `routerdesc`: enable support for the "router descriptor" document type, which
33
//! is needed by bridge clients and relays.
34
//!
35
//! `ns-consensus`: enable support for the "ns consensus" document type, which
36
//! some relays cache and serve.
37
//!
38
//! # Caveat haxxor: limitations and infelicities
39
//!
40
//! TODO: This crate requires that all of its inputs be valid UTF-8:
41
//! This is fine only if we assume that proposal 285 is implemented in
42
//! mainline Tor.
43
//!
44
//! TODO: This crate has several pieces that could probably be split out
45
//! into other smaller cases, including handling for version numbers
46
//! and exit policies.
47
//!
48
//! TODO: Many parts of this crate that should eventually be public
49
//! aren't.
50
//!
51
//! TODO: this crate needs far more tests!
52

            
53
#![deny(missing_docs)]
54
#![warn(noop_method_call)]
55
#![deny(unreachable_pub)]
56
#![warn(clippy::all)]
57
#![deny(clippy::await_holding_lock)]
58
#![deny(clippy::cargo_common_metadata)]
59
#![deny(clippy::cast_lossless)]
60
#![deny(clippy::checked_conversions)]
61
#![warn(clippy::cognitive_complexity)]
62
#![deny(clippy::debug_assert_with_mut_call)]
63
#![deny(clippy::exhaustive_enums)]
64
#![deny(clippy::exhaustive_structs)]
65
#![deny(clippy::expl_impl_clone_on_copy)]
66
#![deny(clippy::fallible_impl_from)]
67
#![deny(clippy::implicit_clone)]
68
#![deny(clippy::large_stack_arrays)]
69
#![warn(clippy::manual_ok_or)]
70
#![deny(clippy::missing_docs_in_private_items)]
71
#![deny(clippy::missing_panics_doc)]
72
#![warn(clippy::needless_borrow)]
73
#![warn(clippy::needless_pass_by_value)]
74
#![warn(clippy::option_option)]
75
#![warn(clippy::rc_buffer)]
76
#![deny(clippy::ref_option_ref)]
77
#![warn(clippy::semicolon_if_nothing_returned)]
78
#![warn(clippy::trait_duplication_in_bounds)]
79
#![deny(clippy::unnecessary_wraps)]
80
#![warn(clippy::unseparated_literal_suffix)]
81
#![deny(clippy::unwrap_used)]
82

            
83
#[macro_use]
84
pub(crate) mod parse;
85
pub mod doc;
86
mod err;
87
pub mod types;
88
mod util;
89

            
90
pub use err::{BuildError, Error, ParseErrorKind, Pos};
91

            
92
/// Alias for the Result type returned by most objects in this module.
93
pub type Result<T> = std::result::Result<T, Error>;
94

            
95
/// Alias for the Result type returned by document-builder functions in this
96
/// module.
97
pub type BuildResult<T> = std::result::Result<T, BuildError>;
98

            
99
/// Indicates whether we should parse an annotated list of objects or a
100
/// non-annotated list.
101
37
#[derive(PartialEq, Debug)]
102
#[allow(clippy::exhaustive_enums)]
103
pub enum AllowAnnotations {
104
    /// Parsing a document where items might be annotated.
105
    ///
106
    /// Annotations are a list of zero or more items with keywords
107
    /// beginning with @ that precede the items that are actually part
108
    /// of the document.
109
    AnnotationsAllowed,
110
    /// Parsing a document where annotations are not allowed.
111
    AnnotationsNotAllowed,
112
}