Skip to content
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
@ChristopherRabotin

Description

@ChristopherRabotin

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:

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!)

Metadata

Metadata

Labels

proposedA proposed functionalityspecificationRelated to the "how should this be done" question

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions