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: u32The 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.
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
impl ProtocolInfoResponse
Sourcepub fn from_message(message: &ControlMessage) -> Result<Self, Error>
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
impl Clone for ProtocolInfoResponse
Source§fn clone(&self) -> ProtocolInfoResponse
fn clone(&self) -> ProtocolInfoResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more