pub trait PtpPacket<HT, BT>{
// Required methods
fn get_header(&self) -> &HT;
fn get_body(&self) -> &BT;
fn get_mac(&self) -> Option<&[u8; 16]>;
fn new(header: HT, body: BT, mac: Option<[u8; 16]>) -> Self;
// Provided methods
fn from_bytes(
data: &[u8],
info: SerializationInfo,
) -> Result<Self, SerializationError>
where Self: Sized { ... }
fn get_bytes(
&self,
info: SerializationInfo,
with_len: bool,
) -> Result<Vec<u8>, SerializationError> { ... }
fn verify_mac(&self, key: &[u8; 32], bucket_key: Option<[u8; 32]>) -> bool { ... }
}
Required Methods§
Sourcefn get_header(&self) -> &HT
fn get_header(&self) -> &HT
Returns the header of the packet
Provided Methods§
Sourcefn from_bytes(
data: &[u8],
info: SerializationInfo,
) -> Result<Self, SerializationError>where
Self: Sized,
fn from_bytes(
data: &[u8],
info: SerializationInfo,
) -> Result<Self, SerializationError>where
Self: Sized,
Deserialize packet from bytes
§Arguments
data
- The bytes to deserializeinfo
- The info to use for deserialization
§Errors
SerializationError::DecryptionFailed
- If the packet is encrypted and the decryption failsSerializationError::MissingInfo
- If the packet is encrypted or authenticated and the info is missingSerializationError::AuthenticationFailed
- If the packet is authenticated and the authentication fails
§Returns
The deserialized packet or an error
Sourcefn get_bytes(
&self,
info: SerializationInfo,
with_len: bool,
) -> Result<Vec<u8>, SerializationError>
fn get_bytes( &self, info: SerializationInfo, with_len: bool, ) -> Result<Vec<u8>, SerializationError>
Sourcefn verify_mac(&self, key: &[u8; 32], bucket_key: Option<[u8; 32]>) -> bool
fn verify_mac(&self, key: &[u8; 32], bucket_key: Option<[u8; 32]>) -> bool
Verifies the MAC of the packet This method is needed so a non-encrypted packet can be checked after deserialization if we do not want to “peek” the header, which is less efficient
§Arguments
key
- The key to verify the MAC with. Must be generated with HKDFbucket_key
- The bucket key to add to the auth_data if authentication is needed. Optional
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.