Uh oh!
There was an error while loading. Please reload this page.
der: remove lifetime from OctetStringRef - #1998
Conversation
tarcieri
commented
Aug 18, 2025
Custom derive needs to be updated to be aware that certain types are reference types and need to be used as e.g. |
8cee1e0 to
2359ca5CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
54b1fbb to
2a06ecaComparetarcieri
commented
Sep 15, 2025
Well, with a few hacks this is green. I think the hacks might be OK to merge with, but we'd ideally want to get them removed before a final release. |
OctetStringRefOctetStringRef| // TODO(tarcieri): custom derive hack until the logic is updated to support `&'a` reference types | ||
| #[doc(hidden)] | ||
| pub type OctetStringRef2<'a> = &'a OctetStringRef; |
There was a problem hiding this comment.
This is one of the hacks. I didn't implement special case support for &'a MyRef types in der_derive yet, so this hack lets it use the old syntax.
Following the pattern of #1921, removes the lifetime from the struct, instead changing `OctetStringRef` to a proper reference type to be used as `&OctetStringRef`. This makes it possible to `impl Borrow<OctetStringRef> for OctetString` and `impl ToOwned for OctetStringRef`, so they can work with `Cow`.
2a06eca to
77c4d20CompareGonna land this. We can work through custom derive support separately. I'll make an issue about it. Edit: opened #2039 |
Uh oh!
There was an error while loading. Please reload this page.
## Added - `Sequence`, `Enumerated` and `Choice` macros now support `#[asn1(error = Ty)]` attribute that provides a custom error type for `Decode`/`DecodeValue` implementations (#1560) - `BitString` macro (#1720, #1733) - `DecodeValue`, `EncodeValue` macros (#1722) - Derive support for `APPLICATION` and `PRIVATE` tags (#1825) - Impl `DecodeValue` for `Choice` (#1986) ## Changed - Use `TryFrom` conversions for `asn1(type = ...)` (#1562) - Rewrite `EncodeValue::value_len` as simple addition (#1810) - Change OctetStringRef `&` handling due to `der` type changes (#1998, #2040, #2043)
## Added - Custom error types support to the `Decode` and `DecodeValue` traits (#1055) - `EncodingRules` enum (#1321) - `Decode::from_ber` (#1389) - Documentation for field-level `tag_mode` attribute (#1401) - `Hash` implementation for `AlgorithmIdentifier` (#1414) - `SequenceRef::as_bytes` and `AsRef<[u8]>` impl (#1454) - `Reader::peek_into` (#1478) - `GeneralString` variant to `Tag` (#1512) - Conversions from `OctetString(Ref)` to `Vec`/`Bytes` (#1540) - Custom error types in derive macros (#1560) - Support for tags beyond 30 (#1651) - Const `::new` to `Length`, `BytesRef`, and `AnyRef` (#1713) - Const `GeneralizedTime::from_date_time` (#1718) - `Decode::from_der_partial` (#1725) - Conversions between `BitStringRef`/`OctetStringRef` and `[u8; N]` (#1731) - Add class bits consts for Application and Private tag support (#1721) - conversions between `heapless:Vec<u8>` and `OctetStringRef` (#1735) - `IsConstructed` trait, impl'ed on any `FixedTag` (#1744) - Implement `Hash` for `SetOf` (#1764) - Implement `Uint`/`Int` conversions from native types (#1762) - Support for `APPLICATION`, `CONTEXT-SPECIFIC` and `PRIVATE` tags (#1819, #1825, #1944) - Support `Cow<[u8]>` in `derive(Sequence)` (#1850) - `diagnostic::on_unimplemented` attributes (#1876) - `Reader::read_value`, auto-nest `DecodeValue` (#1877, #1895, #1897, #1901) - Indefinite length support for BER (#1884, #1885, #1894, #1900, #1902, #1910) - Constructed OctetString support (#1899, #1922) - string conversions, predicate methods for EncodingRules (#1903, #1953) - `Any::header` (#1935) - `Tag::RelativeOid` (#1942) - `ber` feature (#1948, #1950) - Hash derive for `StringOwned` and `Ia5String` (#1973) - Implement `DecodeValue/EncodeValue/Tagged` for `Cow` (#2093) - Add doc examples for `EncodeValue`, `Encode`, `DecodeValue`, `Decode`, `Error`, `ErrorKind`, `Tagged`, `FixedTag`, `IsConstructed`, `Tag`, `Length`, `Header` (#2075, #2071, #2070, #2064, #2058, #2052, #2053, #2051) - `SequenceRef::new` (#2224) ## Changed - Return `Tag::Integer.length_error()` on empty ints (#1400) - Allow all blanket impls on `?Sized` types (#1451) - Refactor `Tag::peek` (#1479) - Refactor `Header::peek` (#1480) - Use `core::error::Error` (#1553) - Use 2024 edition, bump MSRV to 1.85 (#1670) - Bump `const-oid` to v0.10 (#1676) - Reject zero lengths reads (#1716) - Deprecate `TagNumber::new` (#1727) - Use strict context-specific skipping condition (equal tag numbers only) (#1740) - Const `Any::to_ref`, `BytesOwned::to_ref` (#1797) - Return `ErrorKind::Noncanonical` in `EXPLICIT` when primitive (#1818) - Use `read_nested` to check length of `IMPLICIT` types (#1739) - Simplify `From<&UintRef<'a>>` for `Uint` (#1840) - Make `ObjectIdentifier<MAX_SIZE>` impls generic (#1851) - Extract `reader::position::Position` (#1880) - Make `Reader` cloneable (#1883) - Simplify `Header::peek` and `Tag::peek` (#1886) - Improve constructed bit handling (#1919) - Use fat pointer in `OctetStringRef`, consolidate bytes/string modules, improve internal ref types (#1920, #1921, #1998, #2040) - Change constructor `Header::new`, add `Header::with_length`, tests for constructed octet string (#1931, #1930) - Simplify `der_cmp` for `Length` (#1997) - Rename variable encoder -> writer and improve example (#2078) - Have `PemReader` decode to `Cow::Owned` (#2094) - Only sort `SET OF` types with `EncodingRules::Der` (#2219) - `SetOf` and `SequenceOf` now require `heapless` feature (#2220, #2229) ## Fixed - Append in `Encode::encode_to_vec` (#1760) - Derive optional OCTET/BIT STRING on `Option<&[u8]>` (#1737) - X.680 tag order: compare class and number first (#1790) - BMPString compatibility in derive macros (#1793) - `Tag::peek_optional` for 6-byte and 7+ byte tags (#1804) - `Header::peek` for 11-byte tag-lengths (#1828) - Panic in `value_cmp`: add `Iterator::size_hint` (#1830) - Error position tracking improvements (#1889, #2080, #2079) - Bound `Decode(Value)::Error` on `core::error::Error` (#2137) - Have `SetOf(Vec)::insert` check for duplicates (#2217) ## Removed - `TagNumber::N0..N30` consts (#1724) - 256MiB limit on `Length` (#1726) - Generic `<T>` from `Reader::finish` (#1833) - Deprecated `SetOf(Vec)::add` methods (#2232) - `SequenceRef` lifetime (#2224)
Following the pattern of #1921 and what #1998 did for `OctetStringRef`, this removes the lifetime from the struct, instead changing `BitStringRef` to a proper reference type to be used as `&BitStringRef`, which can implement the `Borrow` and `ToOwned` patterns needed to work with `Cow`. To make this work, this uses a hack described in #2298 where we abuse a fat pointer, namely a ZST slice `[UnsafeCell<()>]`, to carry the pointer to the `*const u8` buffer that backs the `BitStringRef`, and carries the bit length along as the length of the ZST slice. To get the original byte length back we can `div_ceil(8)` and then reconstruct the original `[u8]`.
Following the pattern of #1921 and what #1998 did for `OctetStringRef`, this removes the lifetime from the struct, instead changing `BitStringRef` to a proper reference type to be used as `&BitStringRef`, which can implement the `Borrow` and `ToOwned` patterns needed to work with `Cow`. To make this work, this uses a hack described in #2298 where we abuse a fat pointer, namely a ZST slice `[UnsafeCell<()>]`, to carry the pointer to the `*const u8` buffer that backs the `BitStringRef`, and carries the bit length along as the length of the ZST slice. To get the original byte length back we can `div_ceil(8)` and then reconstruct the original `[u8]`.
Following the pattern of #1921 and what #1998 did for `OctetStringRef`, this removes the lifetime from the struct, instead changing `BitStringRef` to a proper reference type to be used as `&BitStringRef`, which can implement the `Borrow` and `ToOwned` patterns needed to work with `Cow`. To make this work, this uses a hack described in #2298 where we abuse a fat pointer, namely a ZST slice `[UnsafeCell<()>]`, to carry the pointer to the `*const u8` buffer that backs the `BitStringRef`, and carries the bit length along as the length of the ZST slice. To get the original byte length back we can `div_ceil(8)` and then reconstruct the original `[u8]`.
Following the pattern of #1921 and what #1998 did for `OctetStringRef`, this removes the lifetime from the struct, instead changing `BitStringRef` to a proper reference type to be used as `&BitStringRef`, which can implement the `Borrow` and `ToOwned` patterns needed to work with `Cow`. To make this work, this uses a hack described in #2298 where we abuse a fat pointer, namely a ZST slice `[UnsafeCell<()>]`, to carry the pointer to the `*const u8` buffer that backs the `BitStringRef`, and carries the bit length along as the length of the ZST slice. To get the original byte length back we can `div_ceil(8)` and then reconstruct the original `[u8]`.
Following the pattern of #1921 and what #1998 did for `OctetStringRef`, this removes the lifetime from the struct, instead changing `BitStringRef` to a proper reference type to be used as `&BitStringRef`, which can implement the `Borrow` and `ToOwned` patterns needed to work with `Cow`. To make this work, this uses a hack described in #2298 where we abuse a fat pointer, namely a ZST slice `[UnsafeCell<()>]`, to carry the pointer to the `*const u8` buffer that backs the `BitStringRef`, and carries the bit length along as the length of the ZST slice. To get the original byte length back we can `div_ceil(8)` and then reconstruct the original `[u8]`.
Following the pattern of #1921 and what #1998 did for `OctetStringRef`, this removes the lifetime from the struct, instead changing `BitStringRef` to a proper reference type to be used as `&BitStringRef`, which can implement the `Borrow` and `ToOwned` patterns needed to work with `Cow`. To make this work, this uses a hack described in #2298 where we abuse a fat pointer, namely a ZST slice `[UnsafeCell<()>]`, to carry the pointer to the `*const u8` buffer that backs the `BitStringRef`, and carries the bit length along as the length of the ZST slice. To get the original byte length back we can `div_ceil(8)` and then reconstruct the original `[u8]`.
Following the pattern of #1921, removes the lifetime from the struct, instead changing
OctetStringRefto a proper reference type to be used as&OctetStringRef.This makes it possible to
impl Borrow<OctetStringRef> for OctetStringandimpl ToOwned for OctetStringRef, so they can work withCow.cc @dishmaker