Giter Site home page Giter Site logo

asn1's Introduction

ASN.1 for Ruby

Currently early stage proof-of-concept.

Requires modified version of asn1c, available here: https://github.com/danielcode/asn1c

Works by wrapping C produced by asn1c.

Creates a separate class for each ASN.1 type.

Supports subset of primitive types and these structured types:

  • SEQUENCE
  • SEQUENCE OF
  • CHOICE

Status

ASN.1 Type Status Ruby Class
ANY Not Implemented
BIT_STRING Implemented Asn1::Type::BitString
BMPString Implemented Asn1::Type::BMPString
BOOLEAN Implemented Asn1::Type::Boolean
ENUMERATED Implemented N/A
GeneralString Unsupported N/A
GeneralizedTime Implemented Asn1::Type::GeneralizedTime
GraphicString Unsupported N/A
IA5String Implemented Asn1::Type::IA5String
INTEGER Implemented Asn1::Type::Integer
ISO646String Implemented Asn1::Type::ISO646String
NULL Implemented Asn1::Type::Null
NumericString Implemented Asn1::Type::NumericString
OBJECT_IDENTIFIER Not Implemented
OCTET_STRING Implemented Asn1::Type::OctetString
ObjectDescriptor Unsupported
PrintableString Implemented Asn1::Type::PrintableString
REAL Not Implemented Asn1::Type::Real
RELATIVE-OID Not Implemented
T61String Unsupported N/A
TeletexString Implemented Asn1::Type::TeletexString
UTCTime Not Implemented
UTF8String Implemented Asn1::Type::UTF8String
UniversalString Implemented Asn1::Type::UniversalString
VideotexString Unsupported
VisibleString Implemented Asn1::Type::VisibleString
CHOICE Implemented N/A
SEQUENCE Implemented N/A
SEQUENCE_OF Implemented N/A
SET Not Implemented N/A
SET_OF Not Implemented N/A

Building

  1. clone and install asn1c:
  2. clone asn1:
  3. cd asn1/ext/asn1
  4. asn1c -fall-defs-global -fwide-types Test.asn1
    • rm Makefile.am.sample
    • rm converter-sample.c
  5. cd ../..
  6. rake compile
  7. rake install_gem

Example Usage

Integer

$ irb
> require 'asn1/asn1'
=> true
> encoded = Asn1::Integer.encode :der, 1234567890
=> "\x02\x04I\x96\x02\xD2"
> Asn1::Integer.decode :der, encoded
=> 1234567890

IA5String

> encoded = Asn1::IA5String.encode :der, 'Hello, world!'
=> "\x16\rHello, world!"
> Asn1::IA5String.decode :der, encoded
=> "Hello, world!"

Sample Sequence

> x = Asn1::Type::SimpleSequence.new
=> #<Asn1::Type::SimpleSequence:0x00000801ca1b20>
> x.simpleString = "Hello, world!"
=> "Hello, world!"
> x.simpleInt = 1
=> 1
> y = Asn1::Schema::SimpleSequence.encode :der, x
=> "0\x12\x02\x01\x01\x16\rHello, world!"
> Asn1::Schema::SimpleSequence.decode :der, y
=> #<Asn1::Type::SimpleSequence:0x00000801c6b728 @simpleString="Hello, world!", @simpleInt=1>

> require 'base64'
=> true
> puts Base64.encode64(y)
MBICAQEWDUhlbGxvLCB3b3JsZCE=

Now, try decoding the base64 encoded string here: http://www.lapo.it/asn1js/

Type Classes

Types are held under Asn1::Type. They include all primitive types and types defined by the user.

Primitive Types

Primitive types currently include:

  • Asn1::Type::Boolean
  • Asn1::Type::IA5String
  • Asn1::Type::Integer
  • Asn1::Type::Null
  • Asn1::Type::Real
  • Asn1::Type::UTF8String

All primitive types have two class methods:

  • encode(format, object)
  • decode(format, object) where format is one of :xer, :der or :per. However, :per does not currently work.

Primitive Type Aliases

Each type alias in an ASN.1 module maps to a type under Asn1::Type.

E.g. MyInt ::= INTEGER => Asn1::Type::MyInt

Complex Types

Complex types have an associated schema, defined under Asn1::Schema

SEQUENCE

SEQUENCE_OF

ENUMERATED

asn1's People

Contributors

danielcode 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.