This repository was archived by the owner on Dec 24, 2023. It is now read-only.
This repository was archived by the owner on Dec 24, 2023. It is now read-only.
Switch from Flatbuffers to ASN.1 ? #10
Open
Description
ASN.1 is a highly efficient standardized platform-independent binary encoding used in lots of applications, including telecommunications and cryptographic key exchanges. This just looks amazing, seriously. Huge thanks to @pwnorbitals for letting me know about this.
Some references:
- https://www.thanassis.space/asn1.html
- https://luca.ntop.org/Teaching/Appunti/asn1.html
- A rust library that supports most of the tags in ASN.1: https://docs.rs/der/
- A cheat sheet reference: https://www.oss.com/asn1/resources/reference/ASN.1-Reference-Card-format-USA.pdf
Note: all of the ASN.1 specs below can be tested directly on this playground: https://asn1.io/asn1playground/ .
Benchmark encoding sizes
One issue with the der
library is that it does not support the Real
type defined in section 2.4 of the specs (PDF).
Rebuilding the REAL type
Built-in
ANISE DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Real ::= SEQUENCE
{
data REAL
}
END
Encode:
value Real ::= {
data 3.141592653589793
}
DER: 26 bytes
Naive
ANISE DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Real ::= SEQUENCE
{
mantissa INTEGER DEFAULT 0,
realbase INTEGER DEFAULT 10,
exponent INTEGER DEFAULT 0
}
END
Encode Pi:
value Real ::= {
mantissa 3141592653589793,
realbase 10,
exponent 15
}
DER: 14 bytes
Full specs
(Took me one hour to fix...)
ANISE DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Normal ::= SEQUENCE
{
mantissa INTEGER DEFAULT 0,
realbase INTEGER DEFAULT 10,
exponent INTEGER DEFAULT 0
}
Subnormal ::= ENUMERATED {
plus-infinity,
neg-infinity
}
Real ::= CHOICE {
as_normal Normal,
as_subnormal Subnormal
}
END
Encoding a normal number:
realdata Real ::= as_normal : {
mantissa 3141592653589793,
realbase 10,
exponent 15
}
DER: 14 bytes ( no overhead it seems!)
Encoding a subnormal number:
realdata Real ::= as_subnormal : plus-infinity
DER: 1 byte (yet, ONE!)