This is a major upgrade, with breaking changes!
The main changes for this version are a custom input type Input for input,
and the new traits BerParser and DerParser. These traits define a cleaner
implementation of parsing functions for header and content, allowing better
implementation of tagged values, of content parsing, and of serialization
functions.
The previous traits (FromBer and FromDer) have been kept for compatibility, but will
become obsolete and will be replaced in future upgrades. This version is a transition version.
Some efforts have been done to make upgrade easier, but a few things are broken or changed and will require manual upgrade.
The main improvements brought by the changes are:
- much easier tracking of parsing errors: the
Inputtype keeps an offset relative to start of input, making it easier to identify the bytes in the encoded object - better support for implicit tags: the new traits
BerParserandDerParserkeep a clean separation of header and data, so now all types implementing these traits can be used with any kind of tags in an easier way - better derive attributes:
Sequence,SetandAliasare better implementations of previous attributes, and new attributes are available:Choice,Enumerated - Serialization support: serialization is now not only experimental (and limited to DER), it is available on all objects, and globally implementation by all new custom derive attributes.
- Support for constructed strings (BER): constructed restricted character strings, bit strings and octet strings are now supported.
Breaking changes:
BerParserandDerParserconstants have been renamed toBerModeandDerMode- Most parsers and objects use
Inputtype (instead of&[u8]) - Error type has changed to
BerError<Input<'_>>and now has a lifetime. While this can cause difficulties for users, it really helps finding errors in the input data
Important changes:
- MSRV is now 1.65
bitvecis now a mandatory dependencyFromDerandFromBerare no more the main traits. They are superseded byDerParserandBerParser- Error type
Erroris not yet removed, but will be removed or replaced byBerErrorin the future - Parsing methods do not rely anymore on
TryFrom<Any> - Custom derive attributes use the
#[cfg(feature="std")condition for generator encoders. This may change in the future - The
debugandtracefeatures now use thelogframework - Many new parsers: tuples (for SEQUENCE), arrays (for SEQUENCE OF
),enum` (for CHOICE or ENUMERATED), iterators, etc.
Upgrade notes:
- To parse a slice, use the
from()method to convert toInput:<T>::parse_ber(Input::from(bytes)) Any.datanow has typeInput. Use.as_bytes2()to get&[u8]- A new error type
BerErrorhas been introduced Any.data()now has typeInput- Use
.as_bytes2()to get&[u8]
- Use
BitStringdo not have a lifetime parameter anymorebitstring.datais replaced bybitstring.as_raw_slice()
Full changelog is quite huge and not included here. It is available on GitHub.
- Update
thiserrorto 2.0 and deriveErrorfor error types (even withno_std)
- Add
ToStaticcustom derive attribute - Add
ToDerSequencecustom derive attribute (#44)
Important:
- Fix a potential panic when using derived parsers, when using custom errors (see #40) This affects only auto-derived parsers specifying a custom error, and parsing incomplete data.
Fixed:
- Fix wrong encoding of large tags (#43)
- Fix wrong encoding of optional TaggedImplicit object (#42)
General:
- Add licences to sub-crates (#38)
- Refactor CI (#36, #41)
- Updates license field to valid SPDX format (#34)
- Daniel McCarney, Łukasz Wojniłowicz, Isaiah Becker-Mayer, Philip Ye
- Provide implementations for
Option<Any>::from_der
General:
- Set MSRV to 1.67.0
- Add PartialEq to SequenceOf and SetOf
- Implement traits for SequenceOf and SetOf to improve usability
- Fix receiver lifetimes in
Anymethods - Implement
BmpString::try_fromfor &Any (so it does not need to consume input) (#26) - oid: change macro to expect dot-separated literals (#28)
- Fix wrong tag in encoding of SET OF (#30)
- Option: require T::Tagged, and check tag before constraints (#27)
- Add missing constructed bit when serializing [2] IMPLICIT) (#18)
- Add methods to convert Any to Real
- Add tag for CHARACTER STRING (29)
- Fix method
Any::as_generalstring(wrong return type) - Add method
Any::as_bmpstring - Fix clippy warnings (1.76.0)
Dependencies updates:
- pem to 3.0
- hex-literal to 0.4
- syn to 2.0
- examples: drop circular dev-dependency caused by oid-registry
- Sergio Benitez, Andrey Chesnokov
- Fix decoding of integers: check if value will wrap if integer is signed
- Fix encoding of integers (add 0x00 prefix when required, and remove extra 0xff for negative integers)
- Fix a small math error in GeneralizedTime
- Introduce trait GetObjectContent, use
from_berwhen skipping BER content (closes #14)
- Nadja Reitzenstein, Christian Speich
Minor fixes:
- Fix constraints too strict on
TaggedValue::FromDer, do not auto-derive - Update oid-registry
- Fix
Any::as_relative_oidto take a reference (and not consume input)
derive:
- Add special case handler for alias to Any
- Add support for DEFAULT attribute
This release adds some new methods and custom derive attributes. It also adds a lot of tests to improve code coverage.
asn1-rs:
- Add helper types for Application/Private tagged values
- Any: add methods
from_ber_and_then(and_der) - TaggedParser: add documentation for
from_ber_and_then(and_der) - Oid: add method
starts_with - Fix documentation of application and private tagged helpers
- Fix clippy warnings
derive:
- Add custom derive BerAlias and DerAlias
coverage:
- Add many tests to improve coverage
Bugfix release:
- Remove explicit output lifetime in traits
- Fix wrong encoding
BmpStringwhen usingToDer - Fix parsing of some EmbeddedPdv subtypes
- Fix encoded length for Enumerated
- Add missing
DerAutoDeriveimpl for bool - Add missing
DerAutoDeriveimpl for f32/f64 - Remove redundant check,
Any::from_derchecks than length is definite - Length: fix potential bug when adding Length + Indefinite
- Fix inverted logic in
Header::assert_definite()
Minor fix:
- add missing file in distribution (fix docs.rs build)
asn1-rs:
- Add generic error parameter in traits and in types
- This was added for all types except a few (like
Vec<T>orBTreeSet<T>) due to Rust compiler limitations
- This was added for all types except a few (like
- Add
DerAutoDerivetrait to control manual/automatic implementation ofFromDer- This allow controlling automatic trait implementation, and providing manual
implementations of both
FromDerandCheckDerConstraints
- This allow controlling automatic trait implementation, and providing manual
implementations of both
- UtcTime: Introduce utc_adjusted_date() to map 2 chars years date to 20/21 centuries date (#9)
derive:
- Add attributes to simplify deriving EXPLICIT, IMPLICIT and OPTIONAL
- Add support for different tag classes (like APPLICATION or PRIVATE)
- Add support for custom errors and mapping errors
- Add support for deriving BER/DER SET
- DerDerive: derive both CheckDerConstraints and FromDer
documentation:
- Add doc modules for recipes and for custom derive attributes
- Add note on trailing bytes being ignored in sequence
- Improve documentation for notation with braces in TaggedValue
- Improve documentation