asn1 2.0.0

ASN.1 encoding and decoding with support for BER, CER, and DER


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

ASN.1 D Library

What is ASN.1?

ASN.1 stands for Abstract Syntax Notation. ASN.1 was first specified in X.680 - Abstract Syntax Notation One (ASN.1), by the International Telecommunications Union. ASN.1 messages can be encoded in one of several encoding/decoding standards. It provides a system of types that are extensible, and can presumably describe every protocol. You can think of it as a protocol for describing other protocols as well as a family of standards for encoding and decoding said protocols. It is similar to Google's Protocol Buffers, or Sun Microsystems' External Data Representation (XDR).

For more information on what ASN.1 is, see documentation/asn1.md.

Why ASN.1?

ASN.1 is used in, or required by, multiple technologies, including:

If you look in the asn1 directory of WireShark's source code, you'll see all of the protocols that use ASN.1.

This list can also be found in documentation/asn1.d.

Building and Installing

There are four scripts in build/scripts that help you build this library, in addition to building using dub. If you are using Windows, you can build by running .\build\scripts\build.ps1 from PowerShell, or .\build\scripts\build.bat from the traditional cmd shell. If you are on any POSIX-compliant(-ish) operating system, such as Linux or Mac OS X, you may build this library using ./build/scripts/build.sh or make -f ./build/scripts/posix.make. The output library will be in ./build/libraries. The command-line tools will be in ./build/executables.

For more information on building and installing, see documentation/install.md.

Library Usage

For each codec in the library, usage entails instantiating the class, then using that class' properties to get and set the encoded value. For all classes, the empty constructor creates an END OF CONTENT element. The remaining constructors will be codec-specific.

Here is an example of encoding with Basic Encoding Rules, using the BERElement class.

BERElement el = new BERElement();
el.typeTag = ASN1UniversalType.integer;
el.integer!long = 1433; // Now the data is encoded.
writefln("%(%02X %)", cast(ubyte[]) el); // Writes the encoded bytes to the terminal.

... and here is how you would decode that same element:

ubyte[] encodedData = cast(ubyte[]) el;
BERElement el2 = new BERElement(encodedData);
long x = el2.integer!long;

For more information on usage of the library, see documentation/library.md, documentation/security.md, documentation/concurrency.md. After that, see the compiler-generated HTML documentation in documentation/html for even more detail.

Command-Line Tools Usage

This library also provides for a pair of command-line tools for each set of encoding rules. The following can be used as a way to read the Distinguished Encoding Rules (DER) structure of an X.509 PEM certificate, for instance:

tail -n +2 example.pem | head -n -1 | base64 --decode | decode-der

For more information on usage of the command-line tools, see documentation/tools.md, or if you are using a POSIX-compliant(-ish) system, run sudo make -f build/scripts/posix.make install to install the man pages, then view them by running man decode-der, for instance.

Development

Version 1.0.0 was released on January 12th, 2018. For a list of all past releases, see documentation/releases.csv. For the plans for future releases, see documentation/roadmap.md. If you would like to contribute (and please do), please see documentation/contributing.md.

Bugs

The codecs are intended to be final classes, but due to this bug I found, it cannot be until that bug is resolved.

Special Thanks

See Also

Contact Me

If you would like to suggest fixes or improvements on this library, please just leave an issue on this GitHub page. If you would like to contact me for other reasons, please email me at [email protected] (My GPG Key) (My TLS Certificate). :boar:

Authors:
Dependencies:
none
Versions:
2.4.3 2018-May-19
2.4.2 2018-May-19
2.4.2-unstable 2018-May-19
2.4.1 2018-May-05
2.4.0 2018-May-01
Show all 18 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 48 downloads total

Score:
1.6
Short URL:
asn1.dub.pm