pub struct Ed25519Extension {
pub ext_type: ExtensionType,
pub type_int: u8,
pub flags: Vec<ExtensionFlag>,
pub flag_int: u8,
pub data: Vec<u8>,
}Expand description
An extension within an Ed25519 certificate.
Extensions provide additional data within a certificate. The most common
extension type is ExtensionType::HasSigningKey, which embeds the
public key used to sign the certificate.
§Structure
Each extension consists of:
- A 2-byte length field (big-endian)
- A 1-byte extension type
- A 1-byte flags field
- Variable-length data
§Flags
The flags field is a bitmask:
- Bit 0 (0x01):
ExtensionFlag::AffectsValidation- Extension is critical - Other bits: Reserved, set
ExtensionFlag::Unknownif present
§Example
use stem_rs::descriptor::certificate::{Ed25519Extension, ExtensionType, ExtensionFlag};
// Create a signing key extension
let signing_key = vec![0u8; 32]; // 32-byte Ed25519 public key
let ext = Ed25519Extension::new(4, 0, signing_key).unwrap();
assert_eq!(ext.ext_type, ExtensionType::HasSigningKey);
assert!(ext.flags.is_empty()); // No flags setFields§
§ext_type: ExtensionTypeThe parsed extension type.
This is the semantic interpretation of type_int.
type_int: u8The raw integer value of the extension type.
Preserved for round-trip encoding of unknown extension types.
flags: Vec<ExtensionFlag>Flags associated with this extension.
See ExtensionFlag for the meaning of each flag.
flag_int: u8The raw integer value of the flags byte.
Preserved for round-trip encoding.
data: Vec<u8>The extension’s data payload.
For ExtensionType::HasSigningKey, this is a 32-byte Ed25519 public key.
Implementations§
Source§impl Ed25519Extension
impl Ed25519Extension
Sourcepub fn new(ext_type: u8, flag_val: u8, data: Vec<u8>) -> Result<Self, Error>
pub fn new(ext_type: u8, flag_val: u8, data: Vec<u8>) -> Result<Self, Error>
Creates a new Ed25519 certificate extension.
§Arguments
ext_type- The extension type as an integerflag_val- The flags bytedata- The extension’s data payload
§Returns
A new Ed25519Extension on success.
§Errors
Returns Error::Parse if:
- The extension type is
ExtensionType::HasSigningKeybut the data is not exactly 32 bytes
§Example
use stem_rs::descriptor::certificate::Ed25519Extension;
// Create a signing key extension (type 4)
let key_data = vec![0u8; 32];
let ext = Ed25519Extension::new(4, 0, key_data).unwrap();
// Invalid: signing key must be 32 bytes
let result = Ed25519Extension::new(4, 0, vec![0u8; 16]);
assert!(result.is_err());Sourcepub fn pack(&self) -> Vec<u8> ⓘ
pub fn pack(&self) -> Vec<u8> ⓘ
Encodes this extension to its binary representation.
The encoded format is:
- 2 bytes: data length (big-endian)
- 1 byte: extension type
- 1 byte: flags
- N bytes: data
§Returns
A byte vector containing the encoded extension.
§Example
use stem_rs::descriptor::certificate::Ed25519Extension;
let ext = Ed25519Extension::new(4, 0, vec![0u8; 32]).unwrap();
let packed = ext.pack();
// 2 (length) + 1 (type) + 1 (flags) + 32 (data) = 36 bytes
assert_eq!(packed.len(), 36);Sourcepub fn pop(content: &[u8]) -> Result<(Self, &[u8]), Error>
pub fn pop(content: &[u8]) -> Result<(Self, &[u8]), Error>
Parses an extension from the beginning of a byte slice.
This method reads one extension from the input and returns both the parsed extension and the remaining unparsed bytes.
§Arguments
content- The byte slice to parse from
§Returns
A tuple of (parsed extension, remaining bytes) on success.
§Errors
Returns Error::Parse if:
- The input is too short to contain the extension header (< 4 bytes)
- The input is truncated (data length exceeds available bytes)
- The extension data is invalid (e.g., wrong size for signing key)
§Example
use stem_rs::descriptor::certificate::Ed25519Extension;
// Extension: length=2, type=5, flags=0, data=[0x11, 0x22]
let data = [0x00, 0x02, 0x05, 0x00, 0x11, 0x22, 0xFF];
let (ext, remaining) = Ed25519Extension::pop(&data).unwrap();
assert_eq!(ext.type_int, 5);
assert_eq!(ext.data, vec![0x11, 0x22]);
assert_eq!(remaining, &[0xFF]); // Remaining byteTrait Implementations§
Source§impl Clone for Ed25519Extension
impl Clone for Ed25519Extension
Source§fn clone(&self) -> Ed25519Extension
fn clone(&self) -> Ed25519Extension
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more