DirectoryAuthority

Struct DirectoryAuthority 

Source
pub struct DirectoryAuthority {
Show 17 fields pub nickname: String, pub v3ident: String, pub hostname: String, pub address: IpAddr, pub dir_port: Option<u16>, pub or_port: u16, pub is_legacy: bool, pub contact: Option<String>, pub vote_digest: Option<String>, pub legacy_dir_key: Option<String>, pub key_certificate: Option<KeyCertificate>, pub is_shared_randomness_participate: bool, pub shared_randomness_commitments: Vec<SharedRandomnessCommitment>, pub shared_randomness_previous_reveal_count: Option<u32>, pub shared_randomness_previous_value: Option<String>, pub shared_randomness_current_reveal_count: Option<u32>, pub shared_randomness_current_value: Option<String>, /* private fields */
}
Expand description

A directory authority entry from a network status document.

Directory authorities are trusted relays that vote on the state of the Tor network. This struct represents an authority’s entry as it appears in vote or consensus documents.

§Conceptual Role

Directory authorities are the backbone of Tor’s distributed trust model. They:

  • Collect and validate relay server descriptors
  • Vote on relay flags (Guard, Exit, Stable, etc.)
  • Produce the network consensus that clients use
  • Participate in shared randomness generation

§Vote vs Consensus Entries

Authority entries differ based on document type:

FieldVoteConsensus
key_certificateRequiredNot present
vote_digestNot presentRequired
legacy_dir_keyMay be presentNot present

§Legacy Authorities

Some authority entries have a -legacy suffix on their nickname, indicating they are legacy entries for backward compatibility. Legacy entries have relaxed validation requirements.

§Example

use stem_rs::descriptor::authority::DirectoryAuthority;

// Parse a consensus authority entry
let content = r#"dir-source gabelmoo F2044413DAC2E02E3D6BCF4735A19BCA1DE97281 131.188.40.189 131.188.40.189 80 443
contact 4096R/261C5FBE77285F88FB0C343266C8C2D7C5AA446D Sebastian Hahn <tor@sebastianhahn.net>
vote-digest 49015F787433103580E3B66A1707A00E60F2D15B
"#;

let authority = DirectoryAuthority::parse(content, false)?;
assert_eq!(authority.nickname, "gabelmoo");
assert!(!authority.is_legacy);

§See Also

Fields§

§nickname: String

The authority’s nickname (1-19 alphanumeric characters). May have a -legacy suffix for legacy entries.

§v3ident: String

The authority’s v3 identity key fingerprint (40 hex characters). Used to identify the authority and verify signatures.

§hostname: String

The authority’s hostname.

§address: IpAddr

The authority’s IP address (IPv4 or IPv6).

§dir_port: Option<u16>

The directory port for HTTP directory requests, or None if not available.

§or_port: u16

The OR (onion router) port for relay traffic.

§is_legacy: bool

Whether this is a legacy authority entry (nickname ends with -legacy).

§contact: Option<String>

Contact information for the authority operator.

§vote_digest: Option<String>

Digest of the authority’s vote (only in consensus documents).

§legacy_dir_key: Option<String>

Legacy directory key fingerprint (only in votes, for backward compatibility).

§key_certificate: Option<KeyCertificate>

The authority’s key certificate (only in vote documents).

§is_shared_randomness_participate: bool

Whether this authority participates in the shared randomness protocol.

§shared_randomness_commitments: Vec<SharedRandomnessCommitment>

Commitments to shared random values from this authority.

§shared_randomness_previous_reveal_count: Option<u32>

Number of authorities that revealed for the previous shared random value.

§shared_randomness_previous_value: Option<String>

The previous shared random value (base64 encoded).

§shared_randomness_current_reveal_count: Option<u32>

Number of authorities that revealed for the current shared random value.

§shared_randomness_current_value: Option<String>

The current shared random value (base64 encoded).

Implementations§

Source§

impl DirectoryAuthority

Source

pub fn parse(content: &str, is_vote: bool) -> Result<Self, Error>

Parses a directory authority entry from its string representation.

This method parses authority entries with full validation enabled. Use parse_with_validation for control over validation behavior.

§Arguments
  • content - The raw authority entry text
  • is_vote - true if parsing from a vote document, false for consensus
§Errors

Returns Error::Parse if:

  • The entry doesn’t start with a dir-source line
  • Required fields are missing or malformed
  • Fingerprints are not valid 40-character hex strings
  • IP addresses or ports are invalid
  • Vote entries lack a key certificate
  • Consensus entries have fields that should only appear in votes
§Example
use stem_rs::descriptor::authority::DirectoryAuthority;

// Parse a consensus entry
let consensus_entry = r#"dir-source moria1 D586D18309DED4CD6D57C18FDB97EFA96D330566 128.31.0.39 128.31.0.39 9131 9101
contact arma
vote-digest 49015F787433103580E3B66A1707A00E60F2D15B
"#;
let authority = DirectoryAuthority::parse(consensus_entry, false)?;
Source

pub fn parse_with_validation( content: &str, validate: bool, is_vote: bool, ) -> Result<Self, Error>

Parses a directory authority entry with configurable validation.

When validation is disabled, the parser is more lenient and will attempt to extract as much information as possible even from malformed entries.

§Arguments
  • content - The raw authority entry text
  • validate - Whether to perform strict validation
  • is_vote - true if parsing from a vote document, false for consensus
§Errors

When validate is true, returns Error::Parse for validation failures. When validate is false, parsing errors are silently ignored where possible.

Source

pub fn raw_content(&self) -> &[u8]

Returns the raw bytes of the authority entry as it appeared in the document.

This preserves the original formatting and can be used for signature verification or re-serialization.

Source

pub fn unrecognized_lines(&self) -> &[String]

Returns lines that were not recognized during parsing.

Unrecognized lines may indicate:

  • New fields added in newer Tor versions
  • Malformed or corrupted data
  • Custom extensions
§Example
use stem_rs::descriptor::authority::DirectoryAuthority;

let content = r#"dir-source test AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA example.com 1.2.3.4 80 443
contact test
unknown-field some-value
vote-digest AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
"#;
let authority = DirectoryAuthority::parse(content, false)?;
assert!(authority.unrecognized_lines().iter().any(|l| l.contains("unknown-field")));
Source

pub fn to_descriptor_string(&self) -> String

Converts the authority entry back to its descriptor string format.

The output follows the Tor directory protocol format and can be used for serialization or debugging.

§Note

The output may not be byte-for-byte identical to the original input due to normalization of whitespace and field ordering.

Trait Implementations§

Source§

impl Clone for DirectoryAuthority

Source§

fn clone(&self) -> DirectoryAuthority

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DirectoryAuthority

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DirectoryAuthority

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for DirectoryAuthority

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for DirectoryAuthority

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for DirectoryAuthority

Source§

fn eq(&self, other: &DirectoryAuthority) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DirectoryAuthority

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.