AddOnionResponse

Struct AddOnionResponse 

Source
pub struct AddOnionResponse {
    pub service_id: String,
    pub private_key: Option<String>,
    pub private_key_type: Option<String>,
    pub client_auth: HashMap<String, String>,
}
Expand description

Parsed response from the ADD_ONION command.

This struct contains the information returned when creating an ephemeral hidden service via the ADD_ONION command. The service exists only for the lifetime of the Tor connection.

§Fields

  • service_id: The .onion address (without the .onion suffix)
  • private_key: The base64-encoded private key (if requested with NEW:BEST or similar)
  • private_key_type: The cryptographic algorithm used (e.g., “RSA1024”, “ED25519-V3”)
  • client_auth: Map of client usernames to their credentials (if client auth enabled)

§Key Types

TypeDescription
RSA1024Legacy v2 hidden service key (deprecated)
ED25519-V3Modern v3 hidden service key (recommended)

§Example

use stem_rs::response::{ControlMessage, AddOnionResponse};

// Response with service ID and private key
let msg = ControlMessage::from_str(
    "250-ServiceID=gfzprpioee3hoppz\r\n\
     250-PrivateKey=ED25519-V3:base64encodedkey\r\n\
     250 OK\r\n",
    None,
    false
).unwrap();

let response = AddOnionResponse::from_message(&msg).unwrap();
assert_eq!(response.service_id, "gfzprpioee3hoppz");
assert_eq!(response.private_key_type, Some("ED25519-V3".to_string()));

§Security Considerations

  • The private key should be stored securely if you need to recreate the service
  • Client auth credentials should be distributed securely to authorized clients
  • Consider using v3 (ED25519-V3) services for better security

Fields§

§service_id: String

The hidden service address without the .onion suffix.

For v2 services, this is a 16-character base32 string. For v3 services, this is a 56-character base32 string.

§private_key: Option<String>

The base64-encoded private key, if requested.

This is only present if the ADD_ONION command included a key generation request (e.g., NEW:BEST or NEW:ED25519-V3). Store this securely if you need to recreate the same hidden service later.

§private_key_type: Option<String>

The type of cryptographic key used.

Common values:

  • "RSA1024": Legacy v2 hidden service (deprecated)
  • "ED25519-V3": Modern v3 hidden service
§client_auth: HashMap<String, String>

Client authentication credentials, if enabled.

Maps client usernames to their base64-encoded credentials. These credentials must be provided to clients for them to access the hidden service.

Implementations§

Source§

impl AddOnionResponse

Source

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

Parses an ADD_ONION response from a control message.

Extracts the service ID, optional private key, and any client authentication credentials from the response.

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

Returns Error::Protocol if:

  • The response status is not OK (2xx)
  • The response doesn’t contain a ServiceID
  • PrivateKey line is malformed (missing : separator)
  • ClientAuth line is malformed (missing : separator)
§Example
use stem_rs::response::{ControlMessage, AddOnionResponse};

// Basic response with just service ID
let msg = ControlMessage::from_str(
    "250-ServiceID=gfzprpioee3hoppz\r\n250 OK\r\n",
    None,
    false
).unwrap();

let response = AddOnionResponse::from_message(&msg).unwrap();
assert_eq!(response.service_id, "gfzprpioee3hoppz");
assert!(response.private_key.is_none());

// Response with client auth
let msg = ControlMessage::from_str(
    "250-ServiceID=test\r\n\
     250-ClientAuth=bob:credential123\r\n\
     250 OK\r\n",
    None,
    false
).unwrap();

let response = AddOnionResponse::from_message(&msg).unwrap();
assert_eq!(response.client_auth.get("bob"), Some(&"credential123".to_string()));

Trait Implementations§

Source§

impl Clone for AddOnionResponse

Source§

fn clone(&self) -> AddOnionResponse

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 AddOnionResponse

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.