Crate bsn1

source ·
Expand description

bsn1 is a rust library to serialize/deserialize in ‘ASN.1’ format.

What is ASN.1?

ASN.1 stands for ‘Abstract Syntax Notation One’ and X.690 is an ‘ITU-T’ standard specifying the following ASN.1 encoding formats.

  • Basic Encoding Rules (BER)
  • Canonical Encoding Rules (CER)
  • Distinguished Encoding Rules (DER)

This crate supports BER and DER for now.

ASN.1 resembles ‘JSON’ in some ways because they both are standard serializing structured data, however, they differ in the following points.

  • JSON is easy for a person to read, on the other hand, ASN.1 is readable for a computer. i.e. ASN.1 consumes less computer resources (e.g. CPU time) than JSON does.
  • There are 4 classes in ASN.1 formats, ‘Universal’, ‘Application’, ‘Context-specific’, and ‘Private’. Class ‘Universal’ defines types like ‘Integer’, ‘Boolean’, ‘String’, ‘Sequence’ and so on like JSON. What is more, ASN.1 allows users to define a new data type using another class.

ASN.1 has been used all over the world for a long time and it is very stable. For example, ‘Transport Layer Security (TLS, SSL)’, ‘Lightweight Directory Access Protocol (LDAP)’, ‘4th Generation Mobile Communication System (4G)’, and so on.

See ‘X.690 (07/2002)’ for details.


Builds a Ber instance representing a Constructed BER effectively.
Builds a Der instance representing ‘Constructed DER’ effectively.


Ber owns BerRef and represents a BER.
BerRef is a wrapper of [u8] and represents a BER.
Contents owns ContentsRef and represents contents octets of ASN.1.
ContentsRef is a wrapper of u8 and represents ‘ASN.1 contents’.
Der owns DerRef and represents ASN.1 DER.
DerRef is a wrapper of [u8] and represents DER.
Id owns IdRef and represents ‘Identifier’.
IdRef is a wrapper of [u8] representing Identifier.


ClassTag represents Tag class of identifier.
Errors for this crate.
Length represents ASN.1 length.
PCTag represents Primitive/Constructed flag of identifier.