This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME
102 lines (75 loc) · 2.3 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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/