socialcast-net-ldap 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/COPYING +272 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +29 -0
- data/Hacking.rdoc +16 -0
- data/History.txt +137 -0
- data/LICENSE +56 -0
- data/Manifest.txt +45 -0
- data/README.txt +70 -0
- data/Rakefile +124 -0
- data/lib/net-ldap.rb +1 -0
- data/lib/net/ber.rb +341 -0
- data/lib/net/ber/ber_parser.rb +168 -0
- data/lib/net/ber/core_ext.rb +72 -0
- data/lib/net/ber/core_ext/array.rb +79 -0
- data/lib/net/ber/core_ext/bignum.rb +19 -0
- data/lib/net/ber/core_ext/false_class.rb +7 -0
- data/lib/net/ber/core_ext/fixnum.rb +63 -0
- data/lib/net/ber/core_ext/string.rb +57 -0
- data/lib/net/ber/core_ext/true_class.rb +9 -0
- data/lib/net/ldap.rb +1539 -0
- data/lib/net/ldap/dataset.rb +174 -0
- data/lib/net/ldap/entry.rb +208 -0
- data/lib/net/ldap/filter.rb +781 -0
- data/lib/net/ldap/password.rb +52 -0
- data/lib/net/ldap/pdu.rb +279 -0
- data/lib/net/ldif.rb +34 -0
- data/lib/net/snmp.rb +295 -0
- data/spec/integration/ssl_ber_spec.rb +33 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/ber/ber_spec.rb +109 -0
- data/spec/unit/ber/core_ext/string_spec.rb +51 -0
- data/spec/unit/ldap/entry_spec.rb +51 -0
- data/spec/unit/ldap/filter_spec.rb +83 -0
- data/spec/unit/ldap_spec.rb +48 -0
- data/test/common.rb +3 -0
- data/test/test_entry.rb +59 -0
- data/test/test_filter.rb +115 -0
- data/test/test_ldif.rb +68 -0
- data/test/test_password.rb +17 -0
- data/test/test_rename.rb +79 -0
- data/test/test_snmp.rb +114 -0
- data/test/testdata.ldif +101 -0
- data/testserver/ldapserver.rb +210 -0
- data/testserver/testdata.ldif +101 -0
- metadata +178 -0
data/LICENSE
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Net::LDAP is copyrighted free software by Francis Cianfrocca
|
2
|
+
<garbagecat10@gmail.com> and other contributors. You can redistribute it and/or
|
3
|
+
modify it under either the terms of the GPL (see the file COPYING), or the
|
4
|
+
conditions below:
|
5
|
+
|
6
|
+
1. You may make and give away verbatim copies of the source form of the
|
7
|
+
software without restriction, provided that you duplicate all of the
|
8
|
+
original copyright notices and associated disclaimers.
|
9
|
+
|
10
|
+
2. You may modify your copy of the software in any way, provided that you do
|
11
|
+
at least ONE of the following:
|
12
|
+
|
13
|
+
a) place your modifications in the Public Domain or otherwise make them
|
14
|
+
Freely Available, such as by posting said modifications to Usenet or
|
15
|
+
an equivalent medium, or by allowing the author to include your
|
16
|
+
modifications in the software.
|
17
|
+
|
18
|
+
b) use the modified software only within your corporation or
|
19
|
+
organization.
|
20
|
+
|
21
|
+
c) rename any non-standard executables so the names do not conflict with
|
22
|
+
standard executables, which must also be provided.
|
23
|
+
|
24
|
+
d) make other distribution arrangements with the author.
|
25
|
+
|
26
|
+
3. You may distribute the software in object code or executable form,
|
27
|
+
provided that you do at least ONE of the following:
|
28
|
+
|
29
|
+
a) distribute the executables and library files of the software, together
|
30
|
+
with instructions (in the manual page or equivalent) on where to get
|
31
|
+
the original distribution.
|
32
|
+
|
33
|
+
b) accompany the distribution with the machine-readable source of the
|
34
|
+
software.
|
35
|
+
|
36
|
+
c) give non-standard executables non-standard names, with instructions on
|
37
|
+
where to get the original software distribution.
|
38
|
+
|
39
|
+
d) make other distribution arrangements with the author.
|
40
|
+
|
41
|
+
4. You may modify and include the part of the software into any other
|
42
|
+
software (possibly commercial). But some files in the distribution are
|
43
|
+
not written by the author, so that they are not under this terms.
|
44
|
+
|
45
|
+
They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
|
46
|
+
files under the ./missing directory. See each file for the copying
|
47
|
+
condition.
|
48
|
+
|
49
|
+
5. The scripts and library files supplied as input to or produced as output
|
50
|
+
from the software do not automatically fall under the copyright of the
|
51
|
+
software, but belong to whomever generated them, and may be sold
|
52
|
+
commercially, and may be aggregated with this software.
|
53
|
+
|
54
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
|
55
|
+
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
56
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
COPYING
|
2
|
+
Gemfile
|
3
|
+
Gemfile.lock
|
4
|
+
Hacking.rdoc
|
5
|
+
History.txt
|
6
|
+
LICENSE
|
7
|
+
Manifest.txt
|
8
|
+
README.txt
|
9
|
+
Rakefile
|
10
|
+
lib/net-ldap.rb
|
11
|
+
lib/net/ber.rb
|
12
|
+
lib/net/ber/ber_parser.rb
|
13
|
+
lib/net/ber/core_ext.rb
|
14
|
+
lib/net/ber/core_ext/array.rb
|
15
|
+
lib/net/ber/core_ext/bignum.rb
|
16
|
+
lib/net/ber/core_ext/false_class.rb
|
17
|
+
lib/net/ber/core_ext/fixnum.rb
|
18
|
+
lib/net/ber/core_ext/string.rb
|
19
|
+
lib/net/ber/core_ext/true_class.rb
|
20
|
+
lib/net/ldap.rb
|
21
|
+
lib/net/ldap/dataset.rb
|
22
|
+
lib/net/ldap/entry.rb
|
23
|
+
lib/net/ldap/filter.rb
|
24
|
+
lib/net/ldap/password.rb
|
25
|
+
lib/net/ldap/pdu.rb
|
26
|
+
lib/net/ldif.rb
|
27
|
+
lib/net/snmp.rb
|
28
|
+
spec/integration/ssl_ber_spec.rb
|
29
|
+
spec/spec.opts
|
30
|
+
spec/spec_helper.rb
|
31
|
+
spec/unit/ber/ber_spec.rb
|
32
|
+
spec/unit/ber/core_ext/string_spec.rb
|
33
|
+
spec/unit/ldap/entry_spec.rb
|
34
|
+
spec/unit/ldap/filter_spec.rb
|
35
|
+
spec/unit/ldap_spec.rb
|
36
|
+
test/common.rb
|
37
|
+
test/test_entry.rb
|
38
|
+
test/test_filter.rb
|
39
|
+
test/test_ldif.rb
|
40
|
+
test/test_password.rb
|
41
|
+
test/test_rename.rb
|
42
|
+
test/test_snmp.rb
|
43
|
+
test/testdata.ldif
|
44
|
+
testserver/ldapserver.rb
|
45
|
+
testserver/testdata.ldif
|
data/README.txt
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
= Net::LDAP for Ruby
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Pure Ruby LDAP library.
|
6
|
+
|
7
|
+
== Where
|
8
|
+
|
9
|
+
=== Issues & Project Homepage
|
10
|
+
|
11
|
+
http://rubyforge.org/projects/net-ldap
|
12
|
+
|
13
|
+
=== Code
|
14
|
+
|
15
|
+
http://github.com/RoryO/ruby-net-ldap/
|
16
|
+
|
17
|
+
== FEATURES/PROBLEMS
|
18
|
+
|
19
|
+
The Lightweight Directory Access Protocol (LDAP) is an Internet protocol for
|
20
|
+
accessing distributed directory services.
|
21
|
+
|
22
|
+
Net::LDAP is an LDAP support library written in pure Ruby. It supports most
|
23
|
+
LDAP client features and a subset of server features as well.
|
24
|
+
|
25
|
+
* Standards-based (going for RFC 4511)
|
26
|
+
* Portable: 100% Ruby
|
27
|
+
|
28
|
+
== SYNOPSIS
|
29
|
+
|
30
|
+
See Net::LDAP for documentation and usage samples.
|
31
|
+
|
32
|
+
== REQUIREMENTS
|
33
|
+
|
34
|
+
Net::LDAP requires Ruby 1.8.7-compliant interpreter or better.
|
35
|
+
|
36
|
+
== INSTALL
|
37
|
+
|
38
|
+
Net::LDAP is a pure Ruby library. It does not require any external libraries.
|
39
|
+
You can install the RubyGems version of Net::LDAP available from the usual
|
40
|
+
sources.
|
41
|
+
|
42
|
+
* gem install net-ldap
|
43
|
+
|
44
|
+
Simply require 'net/ldap'.
|
45
|
+
|
46
|
+
== CREDITS
|
47
|
+
|
48
|
+
Net::LDAP was originally developed by:
|
49
|
+
|
50
|
+
* Francis Cianfrocca blackhedd@rubyforge.org
|
51
|
+
|
52
|
+
Contributions since:
|
53
|
+
|
54
|
+
* Emiel van de Laar emiel@rubyforge.org
|
55
|
+
* Rory O'Connell roryo@rubyforge.org
|
56
|
+
* Kaspar Schiess eule@rubyforge.org
|
57
|
+
* Austin Ziegler austin@rubyforge.org
|
58
|
+
* Dimitrij Denissenko dimdenis@rubyforge.org
|
59
|
+
* "nowhereman" on GitHub
|
60
|
+
|
61
|
+
== LICENSE
|
62
|
+
|
63
|
+
Copyright (C) 2006 - 2010 by Francis Cianfrocca and other contributors.
|
64
|
+
|
65
|
+
Please read the file LICENSE for licensing restrictions on this library. In
|
66
|
+
the simplest terms, this library is available under the same terms as Ruby
|
67
|
+
itself.
|
68
|
+
|
69
|
+
Available under the same terms as Ruby. See LICENSE in the main distribution
|
70
|
+
for full licensing information.
|
data/Rakefile
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
# require 'hanna/rdoctask'
|
3
|
+
require 'hoe'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift('lib')
|
6
|
+
|
7
|
+
require 'net/ldap'
|
8
|
+
|
9
|
+
PKG_NAME = 'socialcast-net-ldap'
|
10
|
+
PKG_VERSION = Net::LDAP::VERSION
|
11
|
+
PKG_DIST = "#{PKG_NAME}-#{PKG_VERSION}"
|
12
|
+
PKG_TAR = "pkg/#{PKG_DIST}.tar.gz"
|
13
|
+
MANIFEST = File.read("Manifest.txt").split
|
14
|
+
MINRUBY = "1.8.7"
|
15
|
+
|
16
|
+
Hoe.plugin :git
|
17
|
+
Hoe.spec PKG_NAME do
|
18
|
+
self.version = PKG_VERSION
|
19
|
+
self.rubyforge_name = PKG_NAME
|
20
|
+
|
21
|
+
developer "Francis Cianfrocca", "blackhedd@rubyforge.org"
|
22
|
+
developer "Emiel van de Laar", "gemiel@gmail.com"
|
23
|
+
developer "Rory O'Connell", "rory.ocon@gmail.com"
|
24
|
+
developer "Kaspar Schiess", "kaspar.schiess@absurd.li"
|
25
|
+
developer "Austin Ziegler", "austin@rubyforge.org"
|
26
|
+
|
27
|
+
self.remote_rdoc_dir = ''
|
28
|
+
rsync_args << ' --exclude=statsvn/'
|
29
|
+
|
30
|
+
self.url = %W(http://net-ldap.rubyforge.org/ http://github.com/RoryO/ruby-net-ldap)
|
31
|
+
|
32
|
+
self.summary = "Pure Ruby LDAP support library with most client features and some server features."
|
33
|
+
self.changes = paragraphs_of(self.history_file, 0..1).join("\n\n")
|
34
|
+
self.description = paragraphs_of(self.readme_file, 2..2).join("\n\n")
|
35
|
+
|
36
|
+
extra_rdoc_files << "Hacking.rdoc"
|
37
|
+
|
38
|
+
extra_dev_deps << [ "archive-tar-minitar", "~>0.5.1" ]
|
39
|
+
extra_dev_deps << [ "hanna", "~>0.1.2" ]
|
40
|
+
extra_dev_deps << [ "hoe-git", "~>1" ]
|
41
|
+
extra_dev_deps << [ "metaid", "~>1" ]
|
42
|
+
clean_globs << "coverage"
|
43
|
+
|
44
|
+
spec_extras[:required_ruby_version] = ">= #{MINRUBY}"
|
45
|
+
multiruby_skip << "1.8.6"
|
46
|
+
multiruby_skip << "1_8_6"
|
47
|
+
|
48
|
+
# This is a lie because I will continue to use Archive::Tar::Minitar.
|
49
|
+
self.need_tar = false
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Build a Net-LDAP .tar.gz distribution."
|
53
|
+
task :tar => [ PKG_TAR ]
|
54
|
+
file PKG_TAR => [ :test ] do |t|
|
55
|
+
require 'archive/tar/minitar'
|
56
|
+
require 'zlib'
|
57
|
+
files = MANIFEST.map { |f|
|
58
|
+
fn = File.join(PKG_DIST, f)
|
59
|
+
tm = File.stat(f).mtime
|
60
|
+
|
61
|
+
if File.directory?(f)
|
62
|
+
{ :name => fn, :mode => 0755, :dir => true, :mtime => tm }
|
63
|
+
else
|
64
|
+
mode = if f =~ %r{^bin}
|
65
|
+
0755
|
66
|
+
else
|
67
|
+
0644
|
68
|
+
end
|
69
|
+
data = File.read(f)
|
70
|
+
{ :name => fn, :mode => mode, :data => data, :size => data.size,
|
71
|
+
:mtime => tm }
|
72
|
+
end
|
73
|
+
}
|
74
|
+
|
75
|
+
begin
|
76
|
+
unless File.directory?(File.dirname(t.name))
|
77
|
+
require 'fileutils'
|
78
|
+
File.mkdir_p File.dirname(t.name)
|
79
|
+
end
|
80
|
+
tf = File.open(t.name, 'wb')
|
81
|
+
gz = Zlib::GzipWriter.new(tf)
|
82
|
+
tw = Archive::Tar::Minitar::Writer.new(gz)
|
83
|
+
|
84
|
+
files.each do |entry|
|
85
|
+
if entry[:dir]
|
86
|
+
tw.mkdir(entry[:name], entry)
|
87
|
+
else
|
88
|
+
tw.add_file_simple(entry[:name], entry) { |os|
|
89
|
+
os.write(entry[:data])
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
ensure
|
94
|
+
tw.close if tw
|
95
|
+
gz.close if gz
|
96
|
+
end
|
97
|
+
end
|
98
|
+
task :package => [ PKG_TAR ]
|
99
|
+
|
100
|
+
desc "Build the manifest file from the current set of files."
|
101
|
+
task :build_manifest do |t|
|
102
|
+
require 'find'
|
103
|
+
|
104
|
+
paths = []
|
105
|
+
Find.find(".") do |path|
|
106
|
+
next if File.directory?(path)
|
107
|
+
next if path =~ /\.svn/
|
108
|
+
next if path =~ /\.git/
|
109
|
+
next if path =~ /\.hoerc/
|
110
|
+
next if path =~ /\.swp$/
|
111
|
+
next if path =~ %r{coverage/}
|
112
|
+
next if path =~ /~$/
|
113
|
+
paths << path.sub(%r{^\./}, '')
|
114
|
+
end
|
115
|
+
|
116
|
+
File.open("Manifest.txt", "w") do |f|
|
117
|
+
f.puts paths.sort.join("\n")
|
118
|
+
end
|
119
|
+
|
120
|
+
puts paths.sort.join("\n")
|
121
|
+
end
|
122
|
+
|
123
|
+
desc "Run a full set of integration and unit tests"
|
124
|
+
task :cruise => [:test, :spec]
|
data/lib/net-ldap.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'net/ldap'
|
data/lib/net/ber.rb
ADDED
@@ -0,0 +1,341 @@
|
|
1
|
+
# NET::BER
|
2
|
+
# Mixes ASN.1/BER convenience methods into several standard classes. Also
|
3
|
+
# provides BER parsing functionality.
|
4
|
+
#
|
5
|
+
#--
|
6
|
+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# Gmail: garbagecat10
|
9
|
+
#
|
10
|
+
# This program is free software; you can redistribute it and/or modify it
|
11
|
+
# under the terms of the GNU General Public License as published by the Free
|
12
|
+
# Software Foundation; either version 2 of the License, or (at your option)
|
13
|
+
# any later version.
|
14
|
+
#
|
15
|
+
# This program is distributed in the hope that it will be useful, but
|
16
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
17
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
18
|
+
# for more details.
|
19
|
+
#
|
20
|
+
# You should have received a copy of the GNU General Public License along
|
21
|
+
# with this program; if not, write to the Free Software Foundation, Inc., 51
|
22
|
+
# Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
23
|
+
#++
|
24
|
+
|
25
|
+
module Net
|
26
|
+
##
|
27
|
+
# == Basic Encoding Rules (BER) Support Module
|
28
|
+
#
|
29
|
+
# Much of the text below is cribbed from Wikipedia:
|
30
|
+
# http://en.wikipedia.org/wiki/Basic_Encoding_Rules
|
31
|
+
#
|
32
|
+
# The ITU Specification is also worthwhile reading:
|
33
|
+
# http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
|
34
|
+
#
|
35
|
+
# The Basic Encoding Rules were the original rules laid out by the ASN.1
|
36
|
+
# standard for encoding abstract information into a concrete data stream.
|
37
|
+
# The rules, collectively referred to as a transfer syntax in ASN.1
|
38
|
+
# parlance, specify the exact octet sequences which are used to encode a
|
39
|
+
# given data item. The syntax defines such elements as: the
|
40
|
+
# representations for basic data types, the structure of length
|
41
|
+
# information, and the means for defining complex or compound types based
|
42
|
+
# on more primitive types. The BER syntax, along with two subsets of BER
|
43
|
+
# (the Canonical Encoding Rules and the Distinguished Encoding Rules), are
|
44
|
+
# defined by the ITU-T's X.690 standards document, which is part of the
|
45
|
+
# ASN.1 document series.
|
46
|
+
#
|
47
|
+
# == Encoding
|
48
|
+
# The BER format specifies a self-describing and self-delimiting format
|
49
|
+
# for encoding ASN.1 data structures. Each data element is encoded as a
|
50
|
+
# type identifier, a length description, the actual data elements, and
|
51
|
+
# where necessary, an end-of-content marker. This format allows a receiver
|
52
|
+
# to decode the ASN.1 information from an incomplete stream, without
|
53
|
+
# requiring any pre-knowledge of the size, content, or semantic meaning of
|
54
|
+
# the data.
|
55
|
+
#
|
56
|
+
# <Type | Length | Value [| End-of-Content]>
|
57
|
+
#
|
58
|
+
# == Protocol Data Units (PDU)
|
59
|
+
# Protocols are defined with schema represented in BER, such that a PDU
|
60
|
+
# consists of cascaded type-length-value encodings.
|
61
|
+
#
|
62
|
+
# === Type Tags
|
63
|
+
# BER type tags are represented as single octets (bytes). The lower five
|
64
|
+
# bits of the octet are tag identifier numbers and the upper three bits of
|
65
|
+
# the octet are used to distinguish the type as native to ASN.1,
|
66
|
+
# application-specific, context-specific, or private. See
|
67
|
+
# Net::BER::TAG_CLASS and Net::BER::ENCODING_TYPE for more information.
|
68
|
+
#
|
69
|
+
# If Class is set to Universal (0b00______), the value is of a type native
|
70
|
+
# to ASN.1 (e.g. INTEGER). The Application class (0b01______) is only
|
71
|
+
# valid for one specific application. Context_specific (0b10______)
|
72
|
+
# depends on the context and private (0b11_______) can be defined in
|
73
|
+
# private specifications
|
74
|
+
#
|
75
|
+
# If the primitive/constructed bit is zero (0b__0_____), it specifies that
|
76
|
+
# the value is primitive like an INTEGER. If it is one (0b__1_____), the
|
77
|
+
# value is a constructed value that contains type-length-value encoded
|
78
|
+
# types like a SET or a SEQUENCE.
|
79
|
+
#
|
80
|
+
# === Defined Universal (ASN.1 Native) Types
|
81
|
+
# There are a number of pre-defined universal (native) types.
|
82
|
+
#
|
83
|
+
# <table>
|
84
|
+
# <tr><th>Name</th><th>Primitive<br />Constructed</th><th>Number</th></tr>
|
85
|
+
# <tr><th>EOC (End-of-Content)</th><th>P</th><td>0: 0 (0x0, 0b00000000)</td></tr>
|
86
|
+
# <tr><th>BOOLEAN</th><th>P</th><td>1: 1 (0x01, 0b00000001)</td></tr>
|
87
|
+
# <tr><th>INTEGER</th><th>P</th><td>2: 2 (0x02, 0b00000010)</td></tr>
|
88
|
+
# <tr><th>BIT STRING</th><th>P</th><td>3: 3 (0x03, 0b00000011)</td></tr>
|
89
|
+
# <tr><th>BIT STRING</th><th>C</th><td>3: 35 (0x23, 0b00100011)</td></tr>
|
90
|
+
# <tr><th>OCTET STRING</th><th>P</th><td>4: 4 (0x04, 0b00000100)</td></tr>
|
91
|
+
# <tr><th>OCTET STRING</th><th>C</th><td>4: 36 (0x24, 0b00100100)</td></tr>
|
92
|
+
# <tr><th>NULL</th><th>P</th><td>5: 5 (0x05, 0b00000101)</td></tr>
|
93
|
+
# <tr><th>OBJECT IDENTIFIER</th><th>P</th><td>6: 6 (0x06, 0b00000110)</td></tr>
|
94
|
+
# <tr><th>Object Descriptor</th><th>P</th><td>7: 7 (0x07, 0b00000111)</td></tr>
|
95
|
+
# <tr><th>EXTERNAL</th><th>C</th><td>8: 40 (0x28, 0b00101000)</td></tr>
|
96
|
+
# <tr><th>REAL (float)</th><th>P</th><td>9: 9 (0x09, 0b00001001)</td></tr>
|
97
|
+
# <tr><th>ENUMERATED</th><th>P</th><td>10: 10 (0x0a, 0b00001010)</td></tr>
|
98
|
+
# <tr><th>EMBEDDED PDV</th><th>C</th><td>11: 43 (0x2b, 0b00101011)</td></tr>
|
99
|
+
# <tr><th>UTF8String</th><th>P</th><td>12: 12 (0x0c, 0b00001100)</td></tr>
|
100
|
+
# <tr><th>UTF8String</th><th>C</th><td>12: 44 (0x2c, 0b00101100)</td></tr>
|
101
|
+
# <tr><th>RELATIVE-OID</th><th>P</th><td>13: 13 (0x0d, 0b00001101)</td></tr>
|
102
|
+
# <tr><th>SEQUENCE and SEQUENCE OF</th><th>C</th><td>16: 48 (0x30, 0b00110000)</td></tr>
|
103
|
+
# <tr><th>SET and SET OF</th><th>C</th><td>17: 49 (0x31, 0b00110001)</td></tr>
|
104
|
+
# <tr><th>NumericString</th><th>P</th><td>18: 18 (0x12, 0b00010010)</td></tr>
|
105
|
+
# <tr><th>NumericString</th><th>C</th><td>18: 50 (0x32, 0b00110010)</td></tr>
|
106
|
+
# <tr><th>PrintableString</th><th>P</th><td>19: 19 (0x13, 0b00010011)</td></tr>
|
107
|
+
# <tr><th>PrintableString</th><th>C</th><td>19: 51 (0x33, 0b00110011)</td></tr>
|
108
|
+
# <tr><th>T61String</th><th>P</th><td>20: 20 (0x14, 0b00010100)</td></tr>
|
109
|
+
# <tr><th>T61String</th><th>C</th><td>20: 52 (0x34, 0b00110100)</td></tr>
|
110
|
+
# <tr><th>VideotexString</th><th>P</th><td>21: 21 (0x15, 0b00010101)</td></tr>
|
111
|
+
# <tr><th>VideotexString</th><th>C</th><td>21: 53 (0x35, 0b00110101)</td></tr>
|
112
|
+
# <tr><th>IA5String</th><th>P</th><td>22: 22 (0x16, 0b00010110)</td></tr>
|
113
|
+
# <tr><th>IA5String</th><th>C</th><td>22: 54 (0x36, 0b00110110)</td></tr>
|
114
|
+
# <tr><th>UTCTime</th><th>P</th><td>23: 23 (0x17, 0b00010111)</td></tr>
|
115
|
+
# <tr><th>UTCTime</th><th>C</th><td>23: 55 (0x37, 0b00110111)</td></tr>
|
116
|
+
# <tr><th>GeneralizedTime</th><th>P</th><td>24: 24 (0x18, 0b00011000)</td></tr>
|
117
|
+
# <tr><th>GeneralizedTime</th><th>C</th><td>24: 56 (0x38, 0b00111000)</td></tr>
|
118
|
+
# <tr><th>GraphicString</th><th>P</th><td>25: 25 (0x19, 0b00011001)</td></tr>
|
119
|
+
# <tr><th>GraphicString</th><th>C</th><td>25: 57 (0x39, 0b00111001)</td></tr>
|
120
|
+
# <tr><th>VisibleString</th><th>P</th><td>26: 26 (0x1a, 0b00011010)</td></tr>
|
121
|
+
# <tr><th>VisibleString</th><th>C</th><td>26: 58 (0x3a, 0b00111010)</td></tr>
|
122
|
+
# <tr><th>GeneralString</th><th>P</th><td>27: 27 (0x1b, 0b00011011)</td></tr>
|
123
|
+
# <tr><th>GeneralString</th><th>C</th><td>27: 59 (0x3b, 0b00111011)</td></tr>
|
124
|
+
# <tr><th>UniversalString</th><th>P</th><td>28: 28 (0x1c, 0b00011100)</td></tr>
|
125
|
+
# <tr><th>UniversalString</th><th>C</th><td>28: 60 (0x3c, 0b00111100)</td></tr>
|
126
|
+
# <tr><th>CHARACTER STRING</th><th>P</th><td>29: 29 (0x1d, 0b00011101)</td></tr>
|
127
|
+
# <tr><th>CHARACTER STRING</th><th>C</th><td>29: 61 (0x3d, 0b00111101)</td></tr>
|
128
|
+
# <tr><th>BMPString</th><th>P</th><td>30: 30 (0x1e, 0b00011110)</td></tr>
|
129
|
+
# <tr><th>BMPString</th><th>C</th><td>30: 62 (0x3e, 0b00111110)</td></tr>
|
130
|
+
# </table>
|
131
|
+
module BER
|
132
|
+
VERSION = '0.1.0'
|
133
|
+
|
134
|
+
##
|
135
|
+
# Used for BER-encoding the length and content bytes of a Fixnum integer
|
136
|
+
# values.
|
137
|
+
MAX_FIXNUM_SIZE = 0.size
|
138
|
+
|
139
|
+
##
|
140
|
+
# BER tag classes are kept in bits seven and eight of the tag type
|
141
|
+
# octet.
|
142
|
+
#
|
143
|
+
# <table>
|
144
|
+
# <tr><th>Bitmask</th><th>Definition</th></tr>
|
145
|
+
# <tr><th><tt>0b00______</tt></th><td>Universal (ASN.1 Native) Types</td></tr>
|
146
|
+
# <tr><th><tt>0b01______</tt></th><td>Application Types</td></tr>
|
147
|
+
# <tr><th><tt>0b10______</tt></th><td>Context-Specific Types</td></tr>
|
148
|
+
# <tr><th><tt>0b11______</tt></th><td>Private Types</td></tr>
|
149
|
+
# </table>
|
150
|
+
TAG_CLASS = {
|
151
|
+
:universal => 0b00000000, # 0
|
152
|
+
:application => 0b01000000, # 64
|
153
|
+
:context_specific => 0b10000000, # 128
|
154
|
+
:private => 0b11000000, # 192
|
155
|
+
}
|
156
|
+
|
157
|
+
##
|
158
|
+
# BER encoding type is kept in bit 6 of the tag type octet.
|
159
|
+
#
|
160
|
+
# <table>
|
161
|
+
# <tr><th>Bitmask</th><th>Definition</th></tr>
|
162
|
+
# <tr><th><tt>0b__0_____</tt></th><td>Primitive</td></tr>
|
163
|
+
# <tr><th><tt>0b__1_____</tt></th><td>Constructed</td></tr>
|
164
|
+
# </table>
|
165
|
+
ENCODING_TYPE = {
|
166
|
+
:primitive => 0b00000000, # 0
|
167
|
+
:constructed => 0b00100000, # 32
|
168
|
+
}
|
169
|
+
|
170
|
+
##
|
171
|
+
# Accepts a hash of hashes describing a BER syntax and converts it into
|
172
|
+
# a byte-keyed object for fast BER conversion lookup. The resulting
|
173
|
+
# "compiled" syntax is used by Net::BER::BERParser.
|
174
|
+
#
|
175
|
+
# This method should be called only by client classes of Net::BER (e.g.,
|
176
|
+
# Net::LDAP and Net::SNMP) and not by clients of those classes.
|
177
|
+
#
|
178
|
+
# The hash-based syntax uses TAG_CLASS keys that contain hashes of
|
179
|
+
# ENCODING_TYPE keys that contain tag numbers with object type markers.
|
180
|
+
#
|
181
|
+
# :<TAG_CLASS> => {
|
182
|
+
# :<ENCODING_TYPE> => {
|
183
|
+
# <number> => <object-type>
|
184
|
+
# },
|
185
|
+
# },
|
186
|
+
#
|
187
|
+
# === Permitted Object Types
|
188
|
+
# <tt>:string</tt>:: A string value, represented as BerIdentifiedString.
|
189
|
+
# <tt>:integer</tt>:: An integer value, represented with Fixnum.
|
190
|
+
# <tt>:oid</tt>:: An Object Identifier value; see X.690 section
|
191
|
+
# 8.19. Currently represented with a standard array,
|
192
|
+
# but may be better represented as a
|
193
|
+
# BerIdentifiedOID object.
|
194
|
+
# <tt>:array</tt>:: A sequence, represented as BerIdentifiedArray.
|
195
|
+
# <tt>:boolean</tt>:: A boolean value, represented as +true+ or +false+.
|
196
|
+
# <tt>:null</tt>:: A null value, represented as BerIdentifiedNull.
|
197
|
+
#
|
198
|
+
# === Example
|
199
|
+
# Net::LDAP defines its ASN.1 BER syntax something like this:
|
200
|
+
#
|
201
|
+
# class Net::LDAP
|
202
|
+
# AsnSyntax = Net::BER.compile_syntax({
|
203
|
+
# :application => {
|
204
|
+
# :primitive => {
|
205
|
+
# 2 => :null,
|
206
|
+
# },
|
207
|
+
# :constructed => {
|
208
|
+
# 0 => :array,
|
209
|
+
# # ...
|
210
|
+
# },
|
211
|
+
# },
|
212
|
+
# :context_specific => {
|
213
|
+
# :primitive => {
|
214
|
+
# 0 => :string,
|
215
|
+
# # ...
|
216
|
+
# },
|
217
|
+
# :constructed => {
|
218
|
+
# 0 => :array,
|
219
|
+
# # ...
|
220
|
+
# },
|
221
|
+
# }
|
222
|
+
# })
|
223
|
+
# end
|
224
|
+
#
|
225
|
+
# NOTE:: For readability and formatting purposes, Net::LDAP and its
|
226
|
+
# siblings actually construct their syntaxes more deliberately,
|
227
|
+
# as shown below. Since a hash is passed in the end in any case,
|
228
|
+
# the format does not matter.
|
229
|
+
#
|
230
|
+
# primitive = { 2 => :null }
|
231
|
+
# constructed = {
|
232
|
+
# 0 => :array,
|
233
|
+
# # ...
|
234
|
+
# }
|
235
|
+
# application = {
|
236
|
+
# :primitive => primitive,
|
237
|
+
# :constructed => constructed
|
238
|
+
# }
|
239
|
+
#
|
240
|
+
# primitive = {
|
241
|
+
# 0 => :string,
|
242
|
+
# # ...
|
243
|
+
# }
|
244
|
+
# constructed = {
|
245
|
+
# 0 => :array,
|
246
|
+
# # ...
|
247
|
+
# }
|
248
|
+
# context_specific = {
|
249
|
+
# :primitive => primitive,
|
250
|
+
# :constructed => constructed
|
251
|
+
# }
|
252
|
+
# AsnSyntax = Net::BER.compile_syntax(:application => application,
|
253
|
+
# :context_specific => context_specific)
|
254
|
+
def self.compile_syntax(syntax)
|
255
|
+
# TODO 20100327 AZ: Should we be allocating an array of 256 values
|
256
|
+
# that will either be +nil+ or an object type symbol, or should we
|
257
|
+
# allocate an empty Hash since unknown values return +nil+ anyway?
|
258
|
+
out = [ nil ] * 256
|
259
|
+
syntax.each do |tag_class_id, encodings|
|
260
|
+
tag_class = TAG_CLASS[tag_class_id]
|
261
|
+
encodings.each do |encoding_id, classes|
|
262
|
+
encoding = ENCODING_TYPE[encoding_id]
|
263
|
+
object_class = tag_class + encoding
|
264
|
+
classes.each do |number, object_type|
|
265
|
+
out[object_class + number] = object_type
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
out
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
class Net::BER::BerError < RuntimeError; end
|
275
|
+
|
276
|
+
##
|
277
|
+
# An Array object with a BER identifier attached.
|
278
|
+
class Net::BER::BerIdentifiedArray < Array
|
279
|
+
attr_accessor :ber_identifier
|
280
|
+
|
281
|
+
def initialize(*args)
|
282
|
+
super
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
##
|
287
|
+
# A BER object identifier.
|
288
|
+
class Net::BER::BerIdentifiedOid
|
289
|
+
attr_accessor :ber_identifier
|
290
|
+
|
291
|
+
def initialize(oid)
|
292
|
+
if oid.is_a?(String)
|
293
|
+
oid = oid.split(/\./).map {|s| s.to_i }
|
294
|
+
end
|
295
|
+
@value = oid
|
296
|
+
end
|
297
|
+
|
298
|
+
def to_ber
|
299
|
+
to_ber_oid
|
300
|
+
end
|
301
|
+
|
302
|
+
def to_ber_oid
|
303
|
+
@value.to_ber_oid
|
304
|
+
end
|
305
|
+
|
306
|
+
def to_s
|
307
|
+
@value.join(".")
|
308
|
+
end
|
309
|
+
|
310
|
+
def to_arr
|
311
|
+
@value.dup
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
##
|
316
|
+
# A String object with a BER identifier attached.
|
317
|
+
class Net::BER::BerIdentifiedString < String
|
318
|
+
attr_accessor :ber_identifier
|
319
|
+
def initialize args
|
320
|
+
super args
|
321
|
+
# LDAP uses UTF-8 encoded strings
|
322
|
+
force_encoding('UTF-8') if respond_to?(:encoding)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
module Net::BER
|
327
|
+
##
|
328
|
+
# A BER null object.
|
329
|
+
class BerIdentifiedNull
|
330
|
+
attr_accessor :ber_identifier
|
331
|
+
def to_ber
|
332
|
+
"\005\000"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
##
|
337
|
+
# The default BerIdentifiedNull object.
|
338
|
+
Null = Net::BER::BerIdentifiedNull.new
|
339
|
+
end
|
340
|
+
|
341
|
+
require 'net/ber/core_ext'
|