ProtocolInfoResponse

Struct ProtocolInfoResponse 

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

Parsed response from the PROTOCOLINFO command.

Contains information about the Tor version and available authentication methods. This is typically used to determine how to authenticate with the control port.

§Example

use stem_rs::response::{ControlMessage, ProtocolInfoResponse, AuthMethod};

let msg = ControlMessage::from_str(
    "250-PROTOCOLINFO 1\r\n\
     250-AUTH METHODS=COOKIE COOKIEFILE=\"/home/user/.tor/control_auth_cookie\"\r\n\
     250-VERSION Tor=\"0.4.7.1\"\r\n\
     250 OK\r\n",
    None,
    false
).unwrap();

let response = ProtocolInfoResponse::from_message(&msg).unwrap();

println!("Protocol version: {}", response.protocol_version);
if let Some(ref version) = response.tor_version {
    println!("Tor version: {}", version);
}
println!("Auth methods: {:?}", response.auth_methods);
if let Some(ref path) = response.cookie_path {
    println!("Cookie file: {}", path.display());
}

Fields§

§protocol_version: u32

The protocol version (typically 1).

This indicates the version of the PROTOCOLINFO response format. Currently, version 1 is the only defined version.

§tor_version: Option<Version>

The Tor version, if provided.

Parsed from the VERSION line of the response. May be None if the VERSION line was not present.

§auth_methods: Vec<AuthMethod>

Available authentication methods.

Lists all authentication methods that Tor will accept. Use this to determine which authentication method to use.

§unknown_auth_methods: Vec<String>

Unrecognized authentication method names.

Contains the raw strings of any authentication methods that weren’t recognized. Useful for debugging or future compatibility.

§cookie_path: Option<PathBuf>

Path to the authentication cookie file, if applicable.

Present when COOKIE or SAFECOOKIE authentication is available. This file must be readable to authenticate using cookie methods.

Implementations§

Source§

impl ProtocolInfoResponse

Source

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

Parses a PROTOCOLINFO response from a control message.

Extracts the protocol version, Tor version, authentication methods, and cookie file path from the response.

§Arguments
  • message - The control message to parse
§Errors

Returns Error::Protocol if:

  • The response status is not OK
  • The response doesn’t start with “PROTOCOLINFO”
  • The protocol version is missing or non-numeric
  • The AUTH line is missing the METHODS mapping
  • The VERSION line is missing the Tor version mapping
  • The Tor version string is invalid
§Example
use stem_rs::response::{ControlMessage, ProtocolInfoResponse, AuthMethod};

// Minimal response (just protocol version)
let msg = ControlMessage::from_str(
    "250-PROTOCOLINFO 1\r\n250 OK\r\n",
    None,
    false
).unwrap();
let response = ProtocolInfoResponse::from_message(&msg).unwrap();
assert_eq!(response.protocol_version, 1);
assert!(response.auth_methods.is_empty());

// Full response with all fields
let msg = ControlMessage::from_str(
    "250-PROTOCOLINFO 1\r\n\
     250-AUTH METHODS=NULL,HASHEDPASSWORD,COOKIE,SAFECOOKIE COOKIEFILE=\"/tmp/cookie\"\r\n\
     250-VERSION Tor=\"0.4.7.1\"\r\n\
     250 OK\r\n",
    None,
    false
).unwrap();
let response = ProtocolInfoResponse::from_message(&msg).unwrap();
assert_eq!(response.auth_methods.len(), 4);

Trait Implementations§

Source§

impl Clone for ProtocolInfoResponse

Source§

fn clone(&self) -> ProtocolInfoResponse

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 ProtocolInfoResponse

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.