pub struct Certificate {
pub cert_type: CertType,
pub type_int: u8,
pub value: Vec<u8>,
}Expand description
A relay certificate as defined in tor-spec section 4.2.
Certificates are used in CERTS cells to authenticate relays during the link handshake. Each certificate has a type and a variable-length value containing the actual certificate data.
§Wire Format
+----------+------------+------------------+
| Type (1) | Length (2) | Value (Len bytes)|
+----------+------------+------------------+Note that the length field is 2 bytes (unlike Address which uses 1 byte).
§Example
use stem_rs::client::datatype::{Certificate, CertType};
// Create a certificate
let cert = Certificate::new(CertType::Link, vec![0x01, 0x02, 0x03]);
assert_eq!(cert.cert_type, CertType::Link);
// Pack and unpack
let packed = cert.pack();
let (unpacked, _) = Certificate::pop(&packed).unwrap();
assert_eq!(cert, unpacked);Fields§
§cert_type: CertTypeThe type of this certificate.
type_int: u8The raw type byte (preserved for unknown types).
value: Vec<u8>The certificate data.
Implementations§
Source§impl Certificate
impl Certificate
Sourcepub fn new(cert_type: CertType, value: Vec<u8>) -> Self
pub fn new(cert_type: CertType, value: Vec<u8>) -> Self
Creates a new certificate with the given type and value.
§Arguments
cert_type- The certificate typevalue- The certificate data
Sourcepub fn from_int(cert_type: u8, value: Vec<u8>) -> Self
pub fn from_int(cert_type: u8, value: Vec<u8>) -> Self
Creates a certificate from a raw type byte and value.
This is used when parsing certificates from the wire format.
§Arguments
cert_type- The raw certificate type bytevalue- The certificate data
Sourcepub fn pack(&self) -> Vec<u8> ⓘ
pub fn pack(&self) -> Vec<u8> ⓘ
Packs the certificate into its wire format.
§Returns
A Vec<u8> containing: [type (1), length (2), value...]
Sourcepub fn pop(content: &[u8]) -> Result<(Self, &[u8]), Error>
pub fn pop(content: &[u8]) -> Result<(Self, &[u8]), Error>
Unpacks a certificate from the start of a byte slice, returning the remainder.
§Arguments
content- The byte slice to read from
§Returns
A tuple of (Certificate, remainder).
§Errors
Returns Error::Protocol if:
- The data is too short for the header
- The specified length exceeds the available data
Trait Implementations§
Source§impl Clone for Certificate
impl Clone for Certificate
Source§fn clone(&self) -> Certificate
fn clone(&self) -> Certificate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more