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
//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
45
#![allow(dead_code, unused_variables)]
46

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

            
55
use macros::define_bytes;
56

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

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

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

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

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

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

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

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