pub struct VCLPacket {
pub version: u8,
pub packet_type: PacketType,
pub sequence: u64,
pub prev_hash: Vec<u8>,
pub nonce: [u8; 24],
pub payload: Vec<u8>,
pub signature: Vec<u8>,
}Expand description
A single unit of data transmission in VCL Protocol.
Packets are created, signed, and serialized internally by VCLConnection.
After recv() returns, payload contains the decrypted data.
Fields§
§version: u8Protocol version. Currently 2.
packet_type: PacketTypeRouting type — see PacketType.
sequence: u64Monotonically increasing sequence number (per direction).
prev_hash: Vec<u8>SHA-256 hash of the previous packet in the same direction. All-zeros for the first packet.
nonce: [u8; 24]24-byte XChaCha20 nonce used to encrypt this packet’s payload.
payload: Vec<u8>After recv(): decrypted payload. On the wire: XChaCha20-Poly1305 ciphertext.
signature: Vec<u8>64-byte Ed25519 signature over the packet hash.
Implementations§
Source§impl VCLPacket
impl VCLPacket
Sourcepub fn new(
sequence: u64,
prev_hash: Vec<u8>,
payload: Vec<u8>,
nonce: [u8; 24],
) -> Self
pub fn new( sequence: u64, prev_hash: Vec<u8>, payload: Vec<u8>, nonce: [u8; 24], ) -> Self
Create a new PacketType::Data packet.
Sourcepub fn new_typed(
sequence: u64,
prev_hash: Vec<u8>,
payload: Vec<u8>,
nonce: [u8; 24],
packet_type: PacketType,
) -> Self
pub fn new_typed( sequence: u64, prev_hash: Vec<u8>, payload: Vec<u8>, nonce: [u8; 24], packet_type: PacketType, ) -> Self
Create a packet with a specific PacketType.
Used internally for Ping, Pong, KeyRotation, and Fragment packets.
Sourcepub fn compute_hash(&self) -> Vec<u8> ⓘ
pub fn compute_hash(&self) -> Vec<u8> ⓘ
Compute the SHA-256 hash of this packet. Used for chain linking and signature generation.
Sourcepub fn sign(&mut self, private_key: &[u8]) -> Result<(), VCLError>
pub fn sign(&mut self, private_key: &[u8]) -> Result<(), VCLError>
Sign this packet with an Ed25519 private_key (32 bytes).
§Errors
Returns VCLError::InvalidKey if private_key is not 32 bytes.
Sourcepub fn verify(&self, public_key: &[u8]) -> Result<bool, VCLError>
pub fn verify(&self, public_key: &[u8]) -> Result<bool, VCLError>
Verify the Ed25519 signature against public_key (32 bytes).
Returns Ok(true) if valid, Ok(false) if the signature does not match.
§Errors
Returns VCLError::InvalidKey if public_key is malformed.
Sourcepub fn validate_chain(&self, expected_prev_hash: &[u8]) -> bool
pub fn validate_chain(&self, expected_prev_hash: &[u8]) -> bool
Returns true if self.prev_hash matches expected_prev_hash.
Sourcepub fn deserialize(data: &[u8]) -> Result<Self, VCLError>
pub fn deserialize(data: &[u8]) -> Result<Self, VCLError>
Deserialize a packet from bytes.
§Errors
Returns VCLError::SerializationError if the bytes are malformed.