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.onionaddress (without the.onionsuffix)private_key: The base64-encoded private key (if requested withNEW:BESTor 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
| Type | Description |
|---|---|
RSA1024 | Legacy v2 hidden service key (deprecated) |
ED25519-V3 | Modern 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: StringThe 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
impl AddOnionResponse
Sourcepub fn from_message(message: &ControlMessage) -> Result<Self, Error>
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
impl Clone for AddOnionResponse
Source§fn clone(&self) -> AddOnionResponse
fn clone(&self) -> AddOnionResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more