Git Product home page Git Product logo

asn1lib's Introduction

ASN.1 Parser for Dart

Encodes & decodes ASN1 using BER encoding.

Samples

Encoding

import 'package:asn1lib/asn1lib.dart';

var s = ASN1Sequence();
s.add(ASN1Integer(23));
s.add(ASN1OctetString('This is a test'));
s.add(ASN1Boolean(true));

// GET the BER Stream
var bytes = s.encodedBytes;

Decoding

import 'package:asn1lib/asn1lib.dart';

// e.g. bytes from the Encoding Example
var p = ASN1Parser(bytes);
var s2 = p.nextObject();
// s2 is a sequence...


// relaxed parsing, returning a generic ASN1Object from (yet) unsupported structures, instead of throwing
var p2 = ASN1Parser(bytes, relaxedParsing: true);
var s3 = p2.nextObject();
// s3 is a sequence...

ASN1 Object classes

The library has been most thoroughly tested against ASN1 primitive class types, such as strings, integers, sequences and sets.

There is minimal support for ASN1 Application, Context-specific and Private classes. If the parser encounters these tags, it will wrap them in an a corresponding object ( ASN1Application, ASN1ContextSpecific, ASN1Private). You can force decode these to another type, by doing something like this:

    var s = parser.nextObject();
    // We expect this is a context-specific class
    expect(s, isA<ASN1ContextSpecific>());
    // which is also an ASN1Object...
    expect(s, isA<ASN1Object>());
    // We expect this is a sequence, so "recast" to a sequence type
    var sequence = ASN1Sequence.fromBytes(s.encodedBytes);
    expect(sequence, isA<ASN1Sequence>()); 

Issues

ASN1 parsing is complex, so bugs are expected. If you find a bug, please provide a test case that demonstrates the issue, along with the expected output. Bonus points if it is formatted as a dart test.

References

asn1lib's People

Contributors

alan-knight avatar amaurel avatar cyberbobs avatar declanwoods avatar dpjanes avatar ephenodrom avatar izik1 avatar jchrist avatar jonaskello avatar kevmoo avatar nico-famedly avatar point-source avatar stevenroose avatar thomaskliszowski avatar wstrange avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.