Skip to main content

Crate tls_codec

Crate tls_codec 

Source
Expand description

§RustCrypto: TLS Codec

MIT licensed Project Chat Image Rust Version

crates.iodocs.rs
tls_codecImageDocs
tls_codec_deriveImageDocs

This crate implements the TLS codec as defined in RFC 8446 as well as some extensions required by MLS.

With the derive feature TlsSerialize and TlsDeserialize can be derived.

The crate also provides the following data structures that implement TLS serialization/deserialization

  • u8, u16, u32, u64, TlsVarInt
  • TlsVecU8, TlsVecU16, TlsVecU32
  • SecretTlsVecU8, SecretTlsVecU16, SecretTlsVecU32 The same as the TlsVec* versions but it implements zeroize, requiring the elements to implement zeroize as well.
  • TlsSliceU8, TlsSliceU16, TlsSliceU32 are lightweight wrapper for slices that allow to serialize them without having to create a TlsVec*.
  • TlsByteSliceU8, TlsByteSliceU16, TlsByteSliceU32, and TlsByteVecU8, TlsByteVecU16, TlsByteVecU32 are provided with optimized implementations for byte vectors.
  • [u8; l], for l ∈ [1..128]
  • Serialize for Option<T> where T: Serialize
  • Deserialize for Option<T> where T: Deserialize
  • Serialize for (T, U) and (T, U, V) where T, U, V implement Serialize`
  • Deserialize for (T, U) and (T, U, V) where T, U, V implement Deserialize`

§Minimum Supported Rust Version (MSRV) Policy

MSRV increases are not considered breaking changes and can happen in patch releases.

The crate MSRV accounts for all supported targets and crate feature combinations, excluding explicitly unstable features.

§License

Licensed under either of:

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

§Usage

use tls_codec::{TlsVecU8, Serialize, Deserialize};
let mut b = &[1u8, 4, 77, 88, 1, 99] as &[u8];

let a = u8::tls_deserialize(&mut b).expect("Unable to tls_deserialize");
assert_eq!(1, a);
println!("b: {:?}", b);
let v = TlsVecU8::<u8>::tls_deserialize(&mut b).expect("Unable to tls_deserialize");
assert_eq!(&[77, 88, 1, 99], v.as_slice());

Modules§

vlenstd

Structs§

SecretTlsVecU8
SecretTlsVecU16
SecretTlsVecU24
SecretTlsVecU32
SecretVLByteVecstd
A wrapper struct around VLByteVec that implements ZeroizeOnDrop. It behaves just like VLByteVec, except that it doesn’t allow conversion into a Vec<u8>.
SecretVLBytesDeprecatedstd
A wrapper struct around VLBytes that implements ZeroizeOnDrop. It behaves just like VLBytes, except that it doesn’t allow conversion into a Vec<u8>.
TlsByteSliceU8
TlsByteSliceU16
TlsByteSliceU24
TlsByteSliceU32
TlsByteVecU8
TlsByteVecU16
TlsByteVecU24
TlsByteVecU32
TlsSliceU8
TlsSliceU16
TlsSliceU24
TlsSliceU32
TlsVarInt
Variable-length encoded unsigned integer as defined in RFC 9000.
TlsVecU8
TlsVecU16
TlsVecU24
TlsVecU32
U24
A 3 byte wide unsigned integer type as defined in RFC 5246.
VLByteSlice
VLByteVec
Variable-length encoded byte vector.
VLBytesDeprecated
Variable-length encoded byte vectors. Use this struct if bytes are encoded. This is faster than the generic version.

Enums§

Error
Errors that are thrown by this crate.

Traits§

Deserialize
The Deserialize trait defines functions to deserialize a byte slice to a struct or enum.
DeserializeBytes
The DeserializeBytes trait defines functions to deserialize a byte slice to a struct or enum. In contrast to Deserialize, this trait operates directly on byte slices and can return any remaining bytes.
Serialize
The Serialize trait provides functions to serialize a struct or enum.
SerializeBytes
The SerializeBytes trait provides a function to serialize a struct or enum.
Size
The Size trait needs to be implemented by any struct that should be efficiently serialized. This allows to collect the length of a serialized structure before allocating memory.

Attribute Macros§

conditionally_deserializableconditional_deserialization
The conditionally_deserializable attribute macro creates two versions of the affected struct: One that implements the Deserialize and DeserializeBytes traits and one that does not. It does so by introducing a boolean const generic that indicates if the struct can be deserialized or not.

Derive Macros§

TlsDeserializederive
TlsDeserializeBytesderive
TlsSerializederive
TlsSerializeBytesderive
TlsSizederive