# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## 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`). `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
- Bumped minimum dependency versions: `zeroize` 1.8 → 1.9, `serde` 1.0.184 → 1.0.228, `serde_bytes` 0.11.17 → 0.11.19.

### Fixed
- [#2348](https://github.com/RustCrypto/formats/pull/2348) Use `write_all` everywhere instead of write to prevent partial writes from going undetected. The `Error::InvalidWriteLength` variant is deprecated as it is no longer returned.
- [#2365](https://github.com/RustCrypto/formats/pull/2365) Element-vector deserialization (`Vec<T>`, `TlsVecU*<T>`, `SecretTlsVecU*<T>`), for both the `Deserialize` (`std::io::Read`) and `DeserializeBytes` implementations, now measures actual byte consumption instead of relying on `tls_serialized_len()` and enforces the declared length exactly. This makes the two implementations agree for non-canonical inner encodings (e.g. non-minimal varint lengths) and rejects input whose elements overshoot the declared vector boundary.
  - Element vectors now reject zero-length elements that would otherwise never advance the read cursor, preventing an infinite loop and unbounded allocation on malicious input.
  - `DeserializeBytes` for `TlsByteVecU*` now uses `checked_add` when computing the content range, returning `Error::InvalidVectorLength` instead of overflowing `usize` on targets where the length field is as wide as the pointer width. (The `VLBytes` / `VLByteVec` deserialization paths were unaffected: the byte-slice path slices via `get(..length)` and the `Read` path bounds allocation via `isize::MAX`, so neither computes an overflowing sum.)
  - Read-based byte-vector deserialization (`TlsByteVecU*`, `VLBytes`, `VLByteVec`) no longer eagerly allocates a buffer sized by the untrusted length field, avoiding large allocations from bogus length prefixes. The `serde` `Deserialize` for `VLByteVec` / `SecretVLByteVec` likewise caps the initial allocation derived from an untrusted `size_hint`.
  - Allocation sites now reject capacities exceeding `isize::MAX` (returning `Error::InvalidVectorLength`) instead of panicking in `Vec::with_capacity`; reachable on 32-bit targets.
  - Fixed swapped doc comments on the `Deserializable*` / `Undeserializable*` type aliases generated by `#[conditionally_deserializable]`.
  - Avoid potential overflows when summing serialized lengths. On 32-bit targets, serialization (including `tls_codec_derive`-generated `Size` impls) can now return `Error::InvalidVectorLength` where the length sum previously wrapped `usize` and produced a truncated, mismatched length prefix on the wire.

## 0.4.2

- [#1628](https://github.com/RustCrypto/formats/pull/1628) Bump MSRV to 1.74

## 0.4.1

- [#1284](https://github.com/RustCrypto/formats/pull/1284): implement `U24`. A `U24` integer type can be used for length encoding in three bytes.
- [#1159](https://github.com/RustCrypto/formats/pull/1159): Read and write all available data in `VLBytes`. Before this change the read or write may have failed when it couldn't be read/written all at once.
- [#1330](https://github.com/RustCrypto/formats/pull/1330): Introduce helper macro for conditional deserialization. This change introduces the `#[tls_codec(cd_field)]` macro. It can be used alongside the `#[conditionally_deserializable]` macro to mark fields that are also conditionally deserializable and that internally need to have the const generic added.

## 0.4.0

### Changed

- [#1251](https://github.com/RustCrypto/formats/pull/1251): Add `_bytes` suffix to function names in the `DeserializeBytes` trait to avoid collisions with function names in the `Deserialize` trait
- [#1135](https://github.com/RustCrypto/formats/pull/1135): `no_std` support for the derive crate. This requires the `std` feature to be enabled when using derive with `Serialize` and `Deserialize`.

### Removed

- [#1251](https://github.com/RustCrypto/formats/pull/1251): Remove the `tls_deserialize_bytes` function from the `Deserialize` trait
