ASN.1 encoder and decoder for Ruby. (based on a porting of Convert::ASN1 for Perl)
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
debian Initial import. Oct 29, 2009
lib Initial import. Oct 29, 2009
test Initial import. Oct 29, 2009
COPYING Initial import. Oct 29, 2009
README Initial import. Oct 29, 2009
TODO Initial import. Oct 29, 2009
rubyasn1.y Initial import. Oct 29, 2009
setup.rb Initial import. Oct 29, 2009



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.


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 =
  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 =
  converter = parser.parse(%<
    AddressBook ::= SEQUENCE OF Person

    Person ::= SEQUENCE {
      name STRING,
      age INTEGER,

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

  # Select a type'AddressBook')

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

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


Copyright(C)2005 MATSUYAMA Kengo <>. 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

setup.rb is copyrighted by Minero Aoki.
For more details, see