1
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
2
#![doc = include_str!("../README.md")]
3
// @@ begin lint list maintained by maint/add_warning @@
4
#![allow(renamed_and_removed_lints)] // @@REMOVE_WHEN(ci_arti_stable)
5
#![allow(unknown_lints)] // @@REMOVE_WHEN(ci_arti_nightly)
6
#![warn(missing_docs)]
7
#![warn(noop_method_call)]
8
#![warn(unreachable_pub)]
9
#![warn(clippy::all)]
10
#![deny(clippy::await_holding_lock)]
11
#![deny(clippy::cargo_common_metadata)]
12
#![deny(clippy::cast_lossless)]
13
#![deny(clippy::checked_conversions)]
14
#![warn(clippy::cognitive_complexity)]
15
#![deny(clippy::debug_assert_with_mut_call)]
16
#![deny(clippy::exhaustive_enums)]
17
#![deny(clippy::exhaustive_structs)]
18
#![deny(clippy::expl_impl_clone_on_copy)]
19
#![deny(clippy::fallible_impl_from)]
20
#![deny(clippy::implicit_clone)]
21
#![deny(clippy::large_stack_arrays)]
22
#![warn(clippy::manual_ok_or)]
23
#![deny(clippy::missing_docs_in_private_items)]
24
#![warn(clippy::needless_borrow)]
25
#![warn(clippy::needless_pass_by_value)]
26
#![warn(clippy::option_option)]
27
#![deny(clippy::print_stderr)]
28
#![deny(clippy::print_stdout)]
29
#![warn(clippy::rc_buffer)]
30
#![deny(clippy::ref_option_ref)]
31
#![warn(clippy::semicolon_if_nothing_returned)]
32
#![warn(clippy::trait_duplication_in_bounds)]
33
#![deny(clippy::unchecked_duration_subtraction)]
34
#![deny(clippy::unnecessary_wraps)]
35
#![warn(clippy::unseparated_literal_suffix)]
36
#![deny(clippy::unwrap_used)]
37
#![deny(clippy::mod_module_files)]
38
#![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness
39
#![allow(clippy::uninlined_format_args)]
40
#![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945
41
#![allow(clippy::result_large_err)] // temporary workaround for arti#587
42
#![allow(clippy::needless_raw_string_hashes)] // complained-about code is fine, often best
43
#![allow(clippy::needless_lifetimes)] // See arti#1765
44
#![allow(mismatched_lifetime_syntaxes)] // temporary workaround for arti#2060
45
//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
46
#![allow(dead_code, unused_variables)]
47

            
48
mod macros;
49
#[cfg(feature = "ope")]
50
pub mod ope;
51
pub mod ops;
52
pub mod pk;
53
pub mod pow;
54
pub mod time;
55

            
56
use macros::define_bytes;
57

            
58
#[cfg(feature = "memquota-memcost")]
59
use {derive_deftly::Deftly, tor_memquota::derive_deftly_template_HasMemoryCost};
60

            
61
define_bytes! {
62
/// A value to identify an onion service during a given period. (`N_hs_subcred`)
63
///
64
/// This is computed from the onion service's public ID and the blinded ID for
65
/// the current time period.
66
///
67
/// Given this piece of information, the original public ID and blinded ID cannot
68
/// be re-derived.
69
#[derive(Copy, Clone, Debug)]
70
pub struct Subcredential([u8; 32]);
71
}
72

            
73
/// Counts which revision of an onion service descriptor is which, within a
74
/// given time period.
75
///
76
/// There can be gaps in this numbering. A descriptor with a higher-valued
77
/// revision counter supersedes one with a lower revision counter.
78
#[derive(
79
    Copy,
80
    Clone,
81
    Debug,
82
    Ord,
83
    PartialOrd,
84
    Eq,
85
    PartialEq,
86
    derive_more::Deref,
87
    derive_more::From,
88
    derive_more::Into,
89
)]
90
pub struct RevisionCounter(u64);
91

            
92
/// Default number of introduction points a service should establish
93
///
94
/// Default value for `[NUM_INTRO_POINT]`, rend-spec-v3 2.5.4.
95
//
96
// TODO arguably these aren't "crypto" so should be in some currently non-existent tor-hscommon
97
pub const NUM_INTRO_POINT_DEF: usize = 3;
98

            
99
/// Maximum number of introduction points a service should establish and we should tolerate
100
///
101
/// Maximum value for `[NUM_INTRO_POINT]`, rend-spec-v3 2.5.4.
102
pub const NUM_INTRO_POINT_MAX: usize = 20;
103

            
104
/// Length of a `RENDEZVOUS` cookie
105
const REND_COOKIE_LEN: usize = 20;
106

            
107
define_bytes! {
108
/// An opaque value `RENDEZVOUS_COOKIE` used at a rendezvous point to match clients and services.
109
///
110
/// See rend-spec-v3 s4.1.
111
///
112
/// The client includes this value to the rendezvous point in its
113
/// `ESTABLISH_RENDEZVOUS` message; the service later provides the same value in its
114
/// `RENDEZVOUS1` message.
115
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
116
#[cfg_attr(
117
    feature = "memquota-memcost",
118
    derive(Deftly),
119
    derive_deftly(HasMemoryCost),
120
)]
121
pub struct RendCookie([u8; REND_COOKIE_LEN]);
122
}
123

            
124
impl rand::distr::Distribution<RendCookie> for rand::distr::StandardUniform {
125
    fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> RendCookie {
126
        RendCookie(rng.random::<[u8; REND_COOKIE_LEN]>().into())
127
    }
128
}