Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tls_codec/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 0.4.3
## 0.5.0

- BREAKING: Rename `SerializeBytes::tls_serialize` to `SerializeBytes::tls_serialize_bytes` to resolve a method-name collision with `Serialize::tls_serialize` (this matches the existing `DeserializeBytes::tls_deserialize_bytes` convention). Any type using `#[tls_codec(with = "...")]` together with `TlsSerializeBytes` must rename its module's `tls_serialize` function to `tls_serialize_bytes` accordingly.
- [#2351](https://github.com/RustCrypto/formats/pull/2351): Implement `Size`, `SerializeBytes`, and `DeserializeBytes` for `String` (and `Size`/`SerializeBytes` for `str` / `&str`), encoding the UTF-8 bytes as a `VLByteVec`. Also implement `SerializeBytes` for `ContentLength` and `VLByteSlice`.
- [#2322](https://github.com/RustCrypto/formats/pull/2322): Add `VLByteVec` and `SecretVLByteVec`, which are `#[serde(transparent)]` wrappers serializing via `serde_bytes`. They produce a much more compact representation in `serde` formats that distinguish byte arrays from sequences of `u8` (e.g. CBOR, MessagePack, bincode). Their `serde` output is not compatible with `VLBytes` / `SecretVLBytes`, but their `Deserialize` impls are backwards-compatible: in self-describing `serde` formats they also accept the legacy `VLBytes` / `SecretVLBytes` encoding (a struct with a `vec` field containing a sequence of `u8`). Deprecate `VLBytes` and `SecretVLBytes` in favour of `VLByteVec` and `SecretVLByteVec`.
- [#2322](https://github.com/RustCrypto/formats/pull/2322): Add `VLByteVec` and `SecretVLByteVec`, which are `#[serde(transparent)]` wrappers serializing via `serde_bytes`. They produce a much more compact representation in `serde` formats that distinguish byte arrays from sequences of `u8` (e.g. CBOR, MessagePack, bincode). Their `serde` output is not compatible with `VLBytes` / `SecretVLBytes`, but their `Deserialize` impls are backwards-compatible: in self-describing `serde` formats they also accept the legacy `VLBytes` / `SecretVLBytes` encoding (a struct with a `vec` field containing a sequence of `u8`). `VLBytes` and `SecretVLBytes` will be deprecated in future in favour of `VLByteVec` and `SecretVLByteVec`.
- [#1656](https://github.com/RustCrypto/formats/pull/1656) Add `TlsVarInt` type for variable-length integers.

### Changed
Expand Down
5 changes: 3 additions & 2 deletions tls_codec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tls_codec"
version = "0.4.3-pre.1"
version = "0.5.0-pre.1"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/tls_codec/"
Expand All @@ -16,7 +16,7 @@ zeroize = { version = "1.9", default-features = false, features = ["alloc"] }

# optional dependencies
arbitrary = { version = "1.4", features = ["derive"], optional = true }
tls_codec_derive = { version = "=0.4.3-pre.1", path = "./derive", optional = true }
tls_codec_derive = { version = "=0.5.0-pre.1", path = "./derive", optional = true }
serde = { version = "1.0.228", features = ["derive"], optional = true }
serde_bytes = { version = "0.11.19", optional = true }

Expand All @@ -36,6 +36,7 @@ conditional_deserialization = [
"derive",
"tls_codec_derive/conditional_deserialization",
]
future_deprecations = []

[[bench]]
name = "tls_vec"
Expand Down
3 changes: 1 addition & 2 deletions tls_codec/benches/quic_vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The benches intentionally exercise the deprecated `VLBytes`.
#![allow(deprecated)]
#![cfg_attr(feature = "future_deprecations", allow(deprecated))]

use criterion::{BatchSize, Criterion};
use criterion::{criterion_group, criterion_main};
Expand Down
8 changes: 7 additions & 1 deletion tls_codec/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tls_codec_derive"
version = "0.4.3-pre.1"
version = "0.5.0-pre.1"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/tls_codec_derive/"
Expand All @@ -27,3 +27,9 @@ trybuild = "1"
default = ["std"]
conditional_deserialization = ["syn/full"]
std = []
# Declared only so the derive tests can gate their `allow(deprecated)` on
# `#[cfg_attr(feature = "future_deprecations", ...)]` without tripping the
# `unexpected_cfgs` lint. It intentionally does not forward to `tls_codec`
# (which is only a dev-dependency here, so it cannot be forwarded to under
# `cargo hack --no-dev-deps`).
future_deprecations = []
18 changes: 9 additions & 9 deletions tls_codec/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ fn impl_serialize(parsed_ast: TlsStruct, svariant: SerializeVariant) -> TokenStr
SerializeVariant::Bytes => {
quote! {
impl #impl_generics tls_codec::SerializeBytes for #ident #ty_generics #where_clause {
fn tls_serialize(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
fn tls_serialize_bytes(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
let expected_out = tls_codec::Size::tls_serialized_len(&self);
// On narrow targets `expected_out` saturates when the serialized
// form exceeds `usize::MAX`; reject it before it reaches
Expand All @@ -987,7 +987,7 @@ fn impl_serialize(parsed_ast: TlsStruct, svariant: SerializeVariant) -> TokenStr
let mut out = Vec::with_capacity(expected_out);

#(
out.append(&mut #prefixes::tls_serialize(&self.#members)?);
out.append(&mut #prefixes::tls_serialize_bytes(&self.#members)?);
)*
if cfg!(debug_assertions) {
debug_assert_eq!(out.len(), expected_out, "Expected to serialize {} bytes but only {} were generated.", expected_out, out.len());
Expand All @@ -1003,8 +1003,8 @@ fn impl_serialize(parsed_ast: TlsStruct, svariant: SerializeVariant) -> TokenStr
}

impl #impl_generics tls_codec::SerializeBytes for &#ident #ty_generics #where_clause {
fn tls_serialize(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
tls_codec::SerializeBytes::tls_serialize(*self)
fn tls_serialize_bytes(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
tls_codec::SerializeBytes::tls_serialize_bytes(*self)
}
}
}
Expand Down Expand Up @@ -1048,8 +1048,8 @@ fn impl_serialize(parsed_ast: TlsStruct, svariant: SerializeVariant) -> TokenStr
.collect::<Vec<_>>();
quote! {
#ident::#variant_id { #(#members: #bindings,)* } => {
let mut discriminant_out = tls_codec::SerializeBytes::tls_serialize(&#discriminant)?;
#(discriminant_out.append(&mut #prefixes::tls_serialize(#bindings)?);)*
let mut discriminant_out = tls_codec::SerializeBytes::tls_serialize_bytes(&#discriminant)?;
#(discriminant_out.append(&mut #prefixes::tls_serialize_bytes(#bindings)?);)*
Ok(discriminant_out)
},
}
Expand Down Expand Up @@ -1090,7 +1090,7 @@ fn impl_serialize(parsed_ast: TlsStruct, svariant: SerializeVariant) -> TokenStr
SerializeVariant::Bytes => {
quote! {
impl #impl_generics tls_codec::SerializeBytes for #ident #ty_generics #where_clause {
fn tls_serialize(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
fn tls_serialize_bytes(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
#discriminant_constants
match self {
#(#arms)*
Expand All @@ -1099,8 +1099,8 @@ fn impl_serialize(parsed_ast: TlsStruct, svariant: SerializeVariant) -> TokenStr
}

impl #impl_generics tls_codec::SerializeBytes for &#ident #ty_generics #where_clause {
fn tls_serialize(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
tls_codec::SerializeBytes::tls_serialize(*self)
fn tls_serialize_bytes(&self) -> core::result::Result<Vec<u8>, tls_codec::Error> {
tls_codec::SerializeBytes::tls_serialize_bytes(*self)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions tls_codec/derive/tests/decode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg(feature = "std")]
// These tests intentionally exercise the deprecated `VLBytes` for backward
// compatibility coverage.
#![allow(deprecated)]
#![cfg_attr(feature = "future_deprecations", allow(deprecated))]
use tls_codec::{
Deserialize, DeserializeBytes, Error, Serialize, Size, TlsSliceU16, TlsVecU8, TlsVecU16,
TlsVecU32, VLBytes,
Expand Down
34 changes: 17 additions & 17 deletions tls_codec/derive/tests/decode_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ struct SomeValue {

#[test]
fn simple_enum() {
let serialized = ExtensionType::KeyId.tls_serialize().unwrap();
let serialized = ExtensionType::KeyId.tls_serialize_bytes().unwrap();
let (deserialized, rest) = ExtensionType::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, ExtensionType::KeyId);
assert!(rest.is_empty());
let serialized = ExtensionType::SomethingElse.tls_serialize().unwrap();
let serialized = ExtensionType::SomethingElse.tls_serialize_bytes().unwrap();
let (deserialized, rest) = ExtensionType::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, ExtensionType::SomethingElse);
assert!(rest.is_empty());
Expand All @@ -47,7 +47,7 @@ fn simple_struct() {
extension_data: vec![1, 2, 3, 4, 5],
additional_data: None,
};
let serialized = extension.tls_serialize().unwrap();
let serialized = extension.tls_serialize_bytes().unwrap();
let (deserialized, rest) = ExtensionStruct::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, extension);
assert!(rest.is_empty());
Expand All @@ -61,7 +61,7 @@ fn tuple_struct() {
additional_data: None,
};
let x = TupleStruct(ext, 6);
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) = TupleStruct::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
assert!(rest.is_empty());
Expand All @@ -70,7 +70,7 @@ fn tuple_struct() {
#[test]
fn byte_arrays() {
let x = [0u8, 1, 2, 3];
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) = <[u8; 4]>::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
assert!(rest.is_empty());
Expand All @@ -90,8 +90,8 @@ mod custom {
v.tls_serialized_len()
}

pub fn tls_serialize(v: &[u8]) -> Result<Vec<u8>, tls_codec::Error> {
v.tls_serialize()
pub fn tls_serialize_bytes(v: &[u8]) -> Result<Vec<u8>, tls_codec::Error> {
v.tls_serialize_bytes()
}

pub fn tls_deserialize_bytes<T: DeserializeBytes>(
Expand All @@ -107,7 +107,7 @@ fn custom() {
values: vec![0, 1, 2],
a: 3,
};
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
assert_eq!(vec![3, 0, 1, 2, 3], serialized);
let (deserialized, rest) = Custom::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
Expand All @@ -123,7 +123,7 @@ enum EnumWithTupleVariant {
#[test]
fn enum_with_tuple_variant() {
let x = EnumWithTupleVariant::A(3, 4);
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) = EnumWithTupleVariant::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
assert!(rest.is_empty());
Expand All @@ -138,7 +138,7 @@ enum EnumWithStructVariant {
#[test]
fn enum_with_struct_variant() {
let x = EnumWithStructVariant::A { foo: 3, bar: 4 };
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) = EnumWithStructVariant::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
assert!(rest.is_empty());
Expand All @@ -155,7 +155,7 @@ enum EnumWithDataAndDiscriminant {
#[test]
fn enum_with_data_and_discriminant() {
let x = EnumWithDataAndDiscriminant::A(4);
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();

let (deserialized, rest) =
EnumWithDataAndDiscriminant::tls_deserialize_bytes(&serialized).unwrap();
Expand All @@ -166,7 +166,7 @@ fn enum_with_data_and_discriminant() {
#[test]
fn discriminant_is_incremented_implicitly() {
let x = EnumWithDataAndDiscriminant::B;
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) =
EnumWithDataAndDiscriminant::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
Expand Down Expand Up @@ -200,22 +200,22 @@ enum EnumWithDataAndConstDiscriminant {
#[test]
fn enum_with_data_and_const_discriminant() {
let x = EnumWithDataAndConstDiscriminant::A(4);
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
assert_eq!(vec![0, 3, 4], serialized);
let (deserialized, rest) =
EnumWithDataAndConstDiscriminant::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
assert!(rest.is_empty());

let x = EnumWithDataAndConstDiscriminant::B;
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) =
EnumWithDataAndConstDiscriminant::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
assert!(rest.is_empty());

let x = EnumWithDataAndConstDiscriminant::C;
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) =
EnumWithDataAndConstDiscriminant::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
Expand All @@ -231,7 +231,7 @@ enum EnumWithCustomSerializedField {
#[test]
fn enum_with_custom_serialized_field() {
let x = EnumWithCustomSerializedField::A(vec![1, 2, 3]);
let serialized = x.tls_serialize().unwrap();
let serialized = x.tls_serialize_bytes().unwrap();
let (deserialized, rest) =
EnumWithCustomSerializedField::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, x);
Expand All @@ -244,7 +244,7 @@ fn that_skip_attribute_on_struct_works() {
where
T: DeserializeBytes + std::fmt::Debug + PartialEq + SerializeBytes + Size,
{
let serialized = test.tls_serialize().unwrap();
let serialized = test.tls_serialize_bytes().unwrap();
let (deserialized, rest) = T::tls_deserialize_bytes(&serialized).unwrap();
assert_eq!(deserialized, expected);
assert!(rest.is_empty());
Expand Down
Loading
Loading