GithubHelp home page GithubHelp logo

rlishtaba / rubyasn1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from macks/rubyasn1

0.0 2.0 0.0 170 KB

ASN.1 encoder and decoder for Ruby. (based on a porting of Convert::ASN1 for Perl)

Home Page: http://wiki.github.com/macks/rubyasn1

License: GNU General Public License v2.0

Ruby 86.60% Bison 13.40%

rubyasn1's Introduction

rubyasn1
========

This library will parse ASN.1 notations and create converter object which
encode Ruby data structures using BER (Basic Encoding Rules) and vice versa.

The library is still EXPERIMENTAL and not implemented completely.
APIs may be changed in future version.


Install
=======

On almost all unix-like systems, type the followings for quick install.

 $ su
 # ruby setup.rb

If you want to customize install directories, type the following for help.

 $ ruby setup.rb --help


How to use
==========

Example 1:

  parser = ASN1::Parser.new
  converter = parser.parse(%<
    seq SEQUENCE {
      integer INTEGER,
      bool BOOLEAN,
      str STRING
    }
  >)

  # Encode
  binary = converter.encode( :seq => {
    :integer => 1, :bool => false, :str => 'A string'
  } )
  p binary
  #=> "0\020\002\001\001\001\001\000\004\bA string"

  # Decode
  object = conter.decode(ber_binary)
  p object
  #=> {:seq=>{:integer=>1, :bool=>false, :str=>"A string"}}


Example 2:

  parser = ASN1::Parser.new
  converter = parser.parse(%<
    AddressBook ::= SEQUENCE OF Person

    Person ::= SEQUENCE {
      name STRING,
      age INTEGER,
      email STRING OPTIONAL
    }
  >)

  # Check compilation error
  if converter.nil?
    puts parser.error
    puts parser.backtrace
    abort
  end

  # Select a type
  converter.select('AddressBook')

  # Encode
  binary = converter.encode([
    { :name => 'Bob',  :age => 24 },
    { :name => 'John', :age => 18, :email => '[email protected]' },
  ])
  p binary
  #=> "0'0\b\004\003Bob\002\001\0300\e\004\004John\002\001\022\004\[email protected]"

  # Decode
  object = converter.decode(binary)
  p object
  #=> [{:age=>24, :name=>"Bob"}, {:age=>18, :email=>"[email protected]", :name=>"John"}]


Copyright
=========

Copyright(C)2005 MATSUYAMA Kengo <[email protected]>. All rights reserved.
This module is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This module is based on a porting of Convert::ASN1 module for Perl.
Convert::ASN1 is copyrighted by Graham Barr.
For more details, see http://search.cpan.org/~gbarr/Convert-ASN1-0.19/

setup.rb is copyrighted by Minero Aoki.
For more details, see http://raa.ruby-lang.org/project/setup/

rubyasn1's People

Contributors

macks avatar

Watchers

James Cloos avatar Roman Lishtaba 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.