ProtocolInfo

Struct ProtocolInfo 

Source
pub struct ProtocolInfo {
    pub protocol_version: u32,
    pub tor_version: Version,
    pub auth_methods: Vec<AuthMethod>,
    pub cookie_path: Option<PathBuf>,
}
Expand description

Information about Tor’s control protocol and authentication requirements.

This struct contains the response from a PROTOCOLINFO query, which must be issued before authentication. It provides:

  • The protocol version supported by Tor
  • The Tor software version
  • Available authentication methods
  • The path to the authentication cookie (if cookie auth is available)

§Invariants

  • protocol_version is typically 1 for all current Tor versions
  • cookie_path is Some only when AuthMethod::Cookie or AuthMethod::SafeCookie is in auth_methods
  • auth_methods may be empty if Tor is misconfigured

§Example

use stem_rs::auth::{get_protocol_info, AuthMethod};
use stem_rs::ControlSocket;

let mut socket = ControlSocket::connect_port("127.0.0.1:9051".parse()?).await?;
let info = get_protocol_info(&mut socket).await?;

println!("Protocol version: {}", info.protocol_version);
println!("Tor version: {}", info.tor_version);

if info.auth_methods.contains(&AuthMethod::SafeCookie) {
    println!("SafeCookie auth available at: {:?}", info.cookie_path);
}

Fields§

§protocol_version: u32

The control protocol version (typically 1).

This indicates the version of the control protocol that Tor speaks. Currently, only version 1 is defined.

§tor_version: Version

The version of the Tor software.

This can be used to check for feature availability or known bugs in specific Tor versions.

§auth_methods: Vec<AuthMethod>

Authentication methods accepted by this Tor instance.

The methods are listed in the order they appear in the PROTOCOLINFO response. Use authenticate to automatically select the best method.

§cookie_path: Option<PathBuf>

Path to the authentication cookie file, if available.

This is Some when cookie-based authentication (AuthMethod::Cookie or AuthMethod::SafeCookie) is available. The path may be absolute or relative to Tor’s data directory.

§Security Note

The cookie file should be readable only by the user running Tor. If you’re in a chroot environment, you may need to adjust this path.

Implementations§

Source§

impl ProtocolInfo

Source

pub fn parse(message: &ControlMessage) -> Result<Self, Error>

Parses a PROTOCOLINFO response from Tor.

This function extracts authentication information from a raw control protocol response. It handles the multi-line PROTOCOLINFO format and extracts all relevant fields.

§Arguments
  • message - The control message containing the PROTOCOLINFO response
§Returns

A ProtocolInfo struct with the parsed information.

§Errors

Returns Error::Protocol if:

  • The response status code indicates failure
  • The response format is malformed
§Example
use stem_rs::auth::{ProtocolInfo, AuthMethod};
use stem_rs::socket::ControlMessage;

let message = ControlMessage {
    status_code: 250,
    lines: vec![
        "PROTOCOLINFO 1".to_string(),
        "AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE=\"/var/run/tor/control.authcookie\"".to_string(),
        "VERSION Tor=\"0.4.7.1\"".to_string(),
        "OK".to_string(),
    ],
};

let info = ProtocolInfo::parse(&message).unwrap();
assert_eq!(info.protocol_version, 1);
assert!(info.auth_methods.contains(&AuthMethod::Cookie));

Trait Implementations§

Source§

impl Clone for ProtocolInfo

Source§

fn clone(&self) -> ProtocolInfo

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 ProtocolInfo

Source§

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

Formats the value using the given formatter. Read more

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.