AuthMethod

Enum AuthMethod 

Source
pub enum AuthMethod {
    None,
    Password,
    Cookie,
    SafeCookie,
}
Expand description

Authentication methods supported by Tor’s control protocol.

These methods are reported by Tor in response to a PROTOCOLINFO query. The authenticate function tries methods in order of security preference: NONE → SAFECOOKIE → COOKIE → PASSWORD.

§Security Comparison

MethodSecurity LevelUse Case
NoneLowestTesting only, never in production
PasswordMediumRemote access with strong password
CookieHighLocal access, older Tor versions
SafeCookieHighestLocal access, Tor 0.2.3+

§Example

use stem_rs::auth::AuthMethod;

let methods = vec![AuthMethod::Cookie, AuthMethod::SafeCookie];
assert!(methods.contains(&AuthMethod::SafeCookie));

Variants§

§

None

No authentication required.

This method is available when Tor’s control port is open without any authentication configured. This is insecure and should only be used for testing or when the control port is bound to localhost and the system is trusted.

Corresponds to NULL in the PROTOCOLINFO response.

§

Password

Password authentication using HashedControlPassword.

Requires a password that matches the hash configured in Tor’s HashedControlPassword torrc option. The password is hex-encoded before transmission.

Corresponds to HASHEDPASSWORD in the PROTOCOLINFO response.

§

Cookie

Cookie file authentication using CookieAuthentication.

Authenticates by presenting the contents of Tor’s authentication cookie file (typically 32 bytes). The cookie path is provided in the PROTOCOLINFO response.

Corresponds to COOKIE in the PROTOCOLINFO response.

§

SafeCookie

HMAC challenge-response authentication (Tor 0.2.3+).

A more secure variant of cookie authentication that uses HMAC-SHA256 challenge-response to prevent replay attacks. The client sends a random nonce, receives a server nonce and hash, verifies the server’s response, then sends its own hash.

Corresponds to SAFECOOKIE in the PROTOCOLINFO response.

Implementations§

Source§

impl AuthMethod

Source

pub fn parse(s: &str) -> Option<Self>

Parses an authentication method from its PROTOCOLINFO string representation.

§Arguments
  • s - The method string from PROTOCOLINFO (case-insensitive)
§Returns

Some(AuthMethod) if recognized, None for unknown methods.

§Examples
use stem_rs::auth::AuthMethod;

assert_eq!(AuthMethod::parse("NULL"), Some(AuthMethod::None));
assert_eq!(AuthMethod::parse("HASHEDPASSWORD"), Some(AuthMethod::Password));
assert_eq!(AuthMethod::parse("cookie"), Some(AuthMethod::Cookie));
assert_eq!(AuthMethod::parse("UNKNOWN"), None);

Trait Implementations§

Source§

impl Clone for AuthMethod

Source§

fn clone(&self) -> AuthMethod

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 AuthMethod

Source§

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

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

impl PartialEq for AuthMethod

Source§

fn eq(&self, other: &AuthMethod) -> 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 Eq for AuthMethod

Source§

impl StructuralPartialEq for AuthMethod

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, 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.