ruby-net-ldap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING ADDED
@@ -0,0 +1,272 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street,
5
+ Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and
6
+ distribute verbatim copies of this license document, but changing it is not
7
+ allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your freedom to
12
+ share and change it. By contrast, the GNU General Public License is
13
+ intended to guarantee your freedom to share and change free software--to
14
+ make sure the software is free for all its users. This General Public
15
+ License applies to most of the Free Software Foundation's software and to
16
+ any other program whose authors commit to using it. (Some other Free
17
+ Software Foundation software is covered by the GNU Lesser General Public
18
+ License instead.) You can apply it to your programs, too.
19
+
20
+ When we speak of free software, we are referring to freedom, not price. Our
21
+ General Public Licenses are designed to make sure that you have the freedom
22
+ to distribute copies of free software (and charge for this service if you
23
+ wish), that you receive source code or can get it if you want it, that you
24
+ can change the software or use pieces of it in new free programs; and that
25
+ you know you can do these things.
26
+
27
+ To protect your rights, we need to make restrictions that forbid anyone to
28
+ deny you these rights or to ask you to surrender the rights. These
29
+ restrictions translate to certain responsibilities for you if you distribute
30
+ copies of the software, or if you modify it.
31
+
32
+ For example, if you distribute copies of such a program, whether gratis or
33
+ for a fee, you must give the recipients all the rights that you have. You
34
+ must make sure that they, too, receive or can get the source code. And you
35
+ must show them these terms so they know their rights.
36
+
37
+ We protect your rights with two steps: (1) copyright the software, and (2)
38
+ offer you this license which gives you legal permission to copy, distribute
39
+ and/or modify the software.
40
+
41
+ Also, for each author's protection and ours, we want to make certain that
42
+ everyone understands that there is no warranty for this free software. If
43
+ the software is modified by someone else and passed on, we want its
44
+ recipients to know that what they have is not the original, so that any
45
+ problems introduced by others will not reflect on the original authors'
46
+ reputations.
47
+
48
+ Finally, any free program is threatened constantly by software patents. We
49
+ wish to avoid the danger that redistributors of a free program will
50
+ individually obtain patent licenses, in effect making the program
51
+ proprietary. To prevent this, we have made it clear that any patent must be
52
+ licensed for everyone's free use or not licensed at all.
53
+
54
+ The precise terms and conditions for copying, distribution and modification
55
+ follow.
56
+
57
+ GNU GENERAL PUBLIC LICENSE
58
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
59
+
60
+ 0. This License applies to any program or other work which contains a notice
61
+ placed by the copyright holder saying it may be distributed under the
62
+ terms of this General Public License. The "Program", below, refers to
63
+ any such program or work, and a "work based on the Program" means either
64
+ the Program or any derivative work under copyright law: that is to say, a
65
+ work containing the Program or a portion of it, either verbatim or with
66
+ modifications and/or translated into another language. (Hereinafter,
67
+ translation is included without limitation in the term "modification".)
68
+ Each licensee is addressed as "you".
69
+
70
+ Activities other than copying, distribution and modification are not
71
+ covered by this License; they are outside its scope. The act of running
72
+ the Program is not restricted, and the output from the Program is covered
73
+ only if its contents constitute a work based on the Program (independent
74
+ of having been made by running the Program). Whether that is true depends
75
+ on what the Program does.
76
+
77
+ 1. You may copy and distribute verbatim copies of the Program's source code
78
+ as you receive it, in any medium, provided that you conspicuously and
79
+ appropriately publish on each copy an appropriate copyright notice and
80
+ disclaimer of warranty; keep intact all the notices that refer to this
81
+ License and to the absence of any warranty; and give any other recipients
82
+ of the Program a copy of this License along with the Program.
83
+
84
+ You may charge a fee for the physical act of transferring a copy, and you
85
+ may at your option offer warranty protection in exchange for a fee.
86
+
87
+ 2. You may modify your copy or copies of the Program or any portion of it,
88
+ thus forming a work based on the Program, and copy and distribute such
89
+ modifications or work under the terms of Section 1 above, provided that
90
+ you also meet all of these conditions:
91
+
92
+ a) You must cause the modified files to carry prominent notices stating
93
+ that you changed the files and the date of any change.
94
+
95
+ b) You must cause any work that you distribute or publish, that in whole
96
+ or in part contains or is derived from the Program or any part
97
+ thereof, to be licensed as a whole at no charge to all third parties
98
+ under the terms of this License.
99
+
100
+ c) If the modified program normally reads commands interactively when
101
+ run, you must cause it, when started running for such interactive use
102
+ in the most ordinary way, to print or display an announcement
103
+ including an appropriate copyright notice and a notice that there is
104
+ no warranty (or else, saying that you provide a warranty) and that
105
+ users may redistribute the program under these conditions, and telling
106
+ the user how to view a copy of this License. (Exception: if the
107
+ Program itself is interactive but does not normally print such an
108
+ announcement, your work based on the Program is not required to print
109
+ an announcement.)
110
+
111
+ These requirements apply to the modified work as a whole. If
112
+ identifiable sections of that work are not derived from the Program, and
113
+ can be reasonably considered independent and separate works in
114
+ themselves, then this License, and its terms, do not apply to those
115
+ sections when you distribute them as separate works. But when you
116
+ distribute the same sections as part of a whole which is a work based on
117
+ the Program, the distribution of the whole must be on the terms of this
118
+ License, whose permissions for other licensees extend to the entire
119
+ whole, and thus to each and every part regardless of who wrote it.
120
+
121
+ Thus, it is not the intent of this section to claim rights or contest
122
+ your rights to work written entirely by you; rather, the intent is to
123
+ exercise the right to control the distribution of derivative or
124
+ collective works based on the Program.
125
+
126
+ In addition, mere aggregation of another work not based on the Program
127
+ with the Program (or with a work based on the Program) on a volume of a
128
+ storage or distribution medium does not bring the other work under the
129
+ scope of this License.
130
+
131
+ 3. You may copy and distribute the Program (or a work based on it, under
132
+ Section 2) in object code or executable form under the terms of Sections
133
+ 1 and 2 above provided that you also do one of the following:
134
+
135
+ a) Accompany it with the complete corresponding machine-readable source
136
+ code, which must be distributed under the terms of Sections 1 and 2
137
+ above on a medium customarily used for software interchange; or,
138
+
139
+ b) Accompany it with a written offer, valid for at least three years, to
140
+ give any third party, for a charge no more than your cost of
141
+ physically performing source distribution, a complete machine-readable
142
+ copy of the corresponding source code, to be distributed under the
143
+ terms of Sections 1 and 2 above on a medium customarily used for
144
+ software interchange; or,
145
+
146
+ c) Accompany it with the information you received as to the offer to
147
+ distribute corresponding source code. (This alternative is allowed
148
+ only for noncommercial distribution and only if you received the
149
+ program in object code or executable form with such an offer, in
150
+ accord with Subsection b above.)
151
+
152
+ The source code for a work means the preferred form of the work for
153
+ making modifications to it. For an executable work, complete source code
154
+ means all the source code for all modules it contains, plus any
155
+ associated interface definition files, plus the scripts used to control
156
+ compilation and installation of the executable. However, as a special
157
+ exception, the source code distributed need not include anything that is
158
+ normally distributed (in either source or binary form) with the major
159
+ components (compiler, kernel, and so on) of the operating system on which
160
+ the executable runs, unless that component itself accompanies the
161
+ executable.
162
+
163
+ If distribution of executable or object code is made by offering access
164
+ to copy from a designated place, then offering equivalent access to copy
165
+ the source code from the same place counts as distribution of the source
166
+ code, even though third parties are not compelled to copy the source
167
+ along with the object code.
168
+
169
+ 4. You may not copy, modify, sublicense, or distribute the Program except as
170
+ expressly provided under this License. Any attempt otherwise to copy,
171
+ modify, sublicense or distribute the Program is void, and will
172
+ automatically terminate your rights under this License. However, parties
173
+ who have received copies, or rights, from you under this License will not
174
+ have their licenses terminated so long as such parties remain in full
175
+ compliance.
176
+
177
+ 5. You are not required to accept this License, since you have not signed
178
+ it. However, nothing else grants you permission to modify or distribute
179
+ the Program or its derivative works. These actions are prohibited by law
180
+ if you do not accept this License. Therefore, by modifying or
181
+ distributing the Program (or any work based on the Program), you indicate
182
+ your acceptance of this License to do so, and all its terms and
183
+ conditions for copying, distributing or modifying the Program or works
184
+ based on it.
185
+
186
+ 6. Each time you redistribute the Program (or any work based on the
187
+ Program), the recipient automatically receives a license from the
188
+ original licensor to copy, distribute or modify the Program subject to
189
+ these terms and conditions. You may not impose any further restrictions
190
+ on the recipients' exercise of the rights granted herein. You are not
191
+ responsible for enforcing compliance by third parties to this License.
192
+
193
+ 7. If, as a consequence of a court judgment or allegation of patent
194
+ infringement or for any other reason (not limited to patent issues),
195
+ conditions are imposed on you (whether by court order, agreement or
196
+ otherwise) that contradict the conditions of this License, they do not
197
+ excuse you from the conditions of this License. If you cannot distribute
198
+ so as to satisfy simultaneously your obligations under this License and
199
+ any other pertinent obligations, then as a consequence you may not
200
+ distribute the Program at all. For example, if a patent license would
201
+ not permit royalty-free redistribution of the Program by all those who
202
+ receive copies directly or indirectly through you, then the only way you
203
+ could satisfy both it and this License would be to refrain entirely from
204
+ distribution of the Program.
205
+
206
+ If any portion of this section is held invalid or unenforceable under any
207
+ particular circumstance, the balance of the section is intended to apply
208
+ and the section as a whole is intended to apply in other circumstances.
209
+
210
+ It is not the purpose of this section to induce you to infringe any
211
+ patents or other property right claims or to contest validity of any such
212
+ claims; this section has the sole purpose of protecting the integrity of
213
+ the free software distribution system, which is implemented by public
214
+ license practices. Many people have made generous contributions to the
215
+ wide range of software distributed through that system in reliance on
216
+ consistent application of that system; it is up to the author/donor to
217
+ decide if he or she is willing to distribute software through any other
218
+ system and a licensee cannot impose that choice.
219
+
220
+ This section is intended to make thoroughly clear what is believed to be
221
+ a consequence of the rest of this License.
222
+
223
+ 8. If the distribution and/or use of the Program is restricted in certain
224
+ countries either by patents or by copyrighted interfaces, the original
225
+ copyright holder who places the Program under this License may add an
226
+ explicit geographical distribution limitation excluding those countries,
227
+ so that distribution is permitted only in or among countries not thus
228
+ excluded. In such case, this License incorporates the limitation as if
229
+ written in the body of this License.
230
+
231
+ 9. The Free Software Foundation may publish revised and/or new versions of
232
+ the General Public License from time to time. Such new versions will be
233
+ similar in spirit to the present version, but may differ in detail to
234
+ address new problems or concerns.
235
+
236
+ Each version is given a distinguishing version number. If the Program
237
+ specifies a version number of this License which applies to it and "any
238
+ later version", you have the option of following the terms and conditions
239
+ either of that version or of any later version published by the Free
240
+ Software Foundation. If the Program does not specify a version number of
241
+ this License, you may choose any version ever published by the Free
242
+ Software Foundation.
243
+
244
+ 10. If you wish to incorporate parts of the Program into other free programs
245
+ whose distribution conditions are different, write to the author to ask
246
+ for permission. For software which is copyrighted by the Free Software
247
+ Foundation, write to the Free Software Foundation; we sometimes make
248
+ exceptions for this. Our decision will be guided by the two goals of
249
+ preserving the free status of all derivatives of our free software and
250
+ of promoting the sharing and reuse of software generally.
251
+
252
+ NO WARRANTY
253
+
254
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
255
+ THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
256
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
257
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
258
+ EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
259
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
260
+ ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH
261
+ YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
262
+ NECESSARY SERVICING, REPAIR OR CORRECTION.
263
+
264
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
265
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
266
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
267
+ DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
268
+ DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
269
+ (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
270
+ INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
271
+ THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR
272
+ OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
@@ -0,0 +1,28 @@
1
+ = Net::LDAP Changelog
2
+
3
+ == Net::LDAP 0.0.1: May 1, 2006
4
+ * Initial release.
5
+ * Client functionality is near-complete, although the APIs
6
+ are not guaranteed and may change depending on feedback
7
+ from the community.
8
+ * We're internally working on a Ruby-based implementation
9
+ of a full-featured, production-quality LDAP server,
10
+ which will leverage the underlying LDAP and BER functionality
11
+ in Net::LDAP.
12
+ * Please tell us if you would be interested in seeing a public
13
+ release of the LDAP server.
14
+ * Grateful acknowledgement to Austin Ziegler, who reviewed
15
+ this code and provided the release framework, including
16
+ minitar.
17
+
18
+ #--
19
+ # Net::LDAP for Ruby.
20
+ # http://rubyforge.org/projects/net-ldap/
21
+ # Copyright (C) 2006 by Francis Cianfrocca
22
+ #
23
+ # Available under the same terms as Ruby. See LICENCE in the main
24
+ # distribution for full licensing information.
25
+ #
26
+ # $Id: ChangeLog,v 1.17.2.4 2005/09/09 12:36:42 austin Exp $
27
+ #++
28
+ # vim: sts=2 sw=2 ts=4 et ai tw=77
data/LICENCE ADDED
@@ -0,0 +1,55 @@
1
+ Net::LDAP is copyrighted free software by Francis Cianfrocca
2
+ <garbagecat10@gmail.com>. You can redistribute it and/or modify it under either
3
+ the terms of the GPL (see the file COPYING), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that you do
10
+ at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise make them
13
+ Freely Available, such as by posting said modifications to Usenet or
14
+ an equivalent medium, or by allowing the author to include your
15
+ modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict with
21
+ standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software, together
29
+ with instructions (in the manual page or equivalent) on where to get
30
+ the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of the
33
+ software.
34
+
35
+ c) give non-standard executables non-standard names, with instructions on
36
+ where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution are
42
+ not written by the author, so that they are not under this terms.
43
+
44
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
+ files under the ./missing directory. See each file for the copying
46
+ condition.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as output
49
+ from the software do not automatically fall under the copyright of the
50
+ software, but belong to whomever generated them, and may be sold
51
+ commercially, and may be aggregated with this software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
54
+ WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
55
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
data/README ADDED
@@ -0,0 +1,29 @@
1
+ = Net::LDAP for Ruby
2
+ Net::LDAP is an LDAP support library written in pure Ruby. It supports all
3
+ LDAP client features, and a subset of server features as well.
4
+
5
+ Homepage:: http://rubyforge.org/projects/net-ldap/
6
+ Copyright:: 2006 by Francis Cianfrocca
7
+
8
+ Original developer: Francis Cianfrocca
9
+ Contributions by Austin Ziegler gratefully acknowledged.
10
+
11
+ == LICENCE NOTES
12
+ Please read the file LICENCE for licensing restrictions on this library. In
13
+ it simplest terms, this library is available under the same terms as Ruby
14
+ itself.
15
+
16
+ == Requirements
17
+ Net::LDAP requires Ruby 1.8.2 or better.
18
+
19
+ #--
20
+ # Net::LDAP for Ruby.
21
+ # http://rubyforge.org/projects/net-ldap/
22
+ # Copyright (C) 2006 by Francis Cianfrocca
23
+ #
24
+ # Available under the same terms as Ruby. See LICENCE in the main
25
+ # distribution for full licensing information.
26
+ #
27
+ # $Id: README 82 2006-04-30 11:36:18Z blackhedd $
28
+ #++
29
+ # vim: sts=2 sw=2 ts=4 et ai tw=77
@@ -0,0 +1,278 @@
1
+ # $Id: ber.rb 93 2006-05-01 06:40:48Z blackhedd $
2
+ #
3
+ # NET::BER
4
+ # Mixes ASN.1/BER convenience methods into several standard classes.
5
+ # Also provides BER parsing functionality.
6
+ #
7
+ #----------------------------------------------------------------------------
8
+ #
9
+ # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
10
+ #
11
+ # Gmail: garbagecat10
12
+ #
13
+ # This program is free software; you can redistribute it and/or modify
14
+ # it under the terms of the GNU General Public License as published by
15
+ # the Free Software Foundation; either version 2 of the License, or
16
+ # (at your option) any later version.
17
+ #
18
+ # This program is distributed in the hope that it will be useful,
19
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ # GNU General Public License for more details.
22
+ #
23
+ # You should have received a copy of the GNU General Public License
24
+ # along with this program; if not, write to the Free Software
25
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ #
27
+ #---------------------------------------------------------------------------
28
+ #
29
+ #
30
+
31
+
32
+
33
+
34
+ module Net
35
+
36
+ module BER
37
+
38
+ class BerError < Exception; end
39
+
40
+
41
+ # This module is for mixing into IO and IO-like objects.
42
+ module BERParser
43
+
44
+ # The order of these follows the class-codes in BER.
45
+ # Maybe this should have been a hash.
46
+ TagClasses = [:universal, :application, :context_specific, :private]
47
+
48
+ BuiltinSyntax = {
49
+ :universal => {
50
+ :primitive => {
51
+ 1 => :boolean,
52
+ 2 => :integer,
53
+ 4 => :string,
54
+ 10 => :integer,
55
+ },
56
+ :constructed => {
57
+ 16 => :array,
58
+ 17 => :array
59
+ }
60
+ }
61
+ }
62
+
63
+ #
64
+ # read_ber
65
+ # TODO: clean this up so it works properly with partial
66
+ # packets coming from streams that don't block when
67
+ # we ask for more data (like StringIOs). At it is,
68
+ # this can throw TypeErrors and other nasties.
69
+ #
70
+ def read_ber syntax=nil
71
+ return nil if eof?
72
+
73
+ id = getc # don't trash this value, we'll use it later
74
+ tag = id & 31
75
+ tag < 31 or raise BerError.new( "unsupported tag encoding: #{id}" )
76
+ tagclass = TagClasses[ id >> 6 ]
77
+ encoding = (id & 0x20 != 0) ? :constructed : :primitive
78
+
79
+ n = getc
80
+ lengthlength,contentlength = if n <= 127
81
+ [1,n]
82
+ else
83
+ j = (0...(n & 127)).inject(0) {|mem,x| mem = (mem << 8) + getc}
84
+ [1 + (n & 127), j]
85
+ end
86
+
87
+ newobj = read contentlength
88
+
89
+ objtype = nil
90
+ [syntax, BuiltinSyntax].each {|syn|
91
+ if syn && (ot = syn[tagclass]) && (ot = ot[encoding]) && ot[tag]
92
+ objtype = ot[tag]
93
+ break
94
+ end
95
+ }
96
+
97
+ obj = case objtype
98
+ when :boolean
99
+ newobj != "\000"
100
+ when :string
101
+ (newobj || "").dup
102
+ when :integer
103
+ j = 0
104
+ newobj.each_byte {|b| j = (j << 8) + b}
105
+ j
106
+ when :array
107
+ seq = []
108
+ sio = StringIO.new( newobj || "" )
109
+ # Interpret the subobject, but note how the loop
110
+ # is built: nil ends the loop, but false (a valid
111
+ # BER value) does not!
112
+ while (e = sio.read_ber(syntax)) != nil
113
+ seq << e
114
+ end
115
+ seq
116
+ else
117
+ raise BerError.new( "unsupported object type: class=#{tagclass}, encoding=#{encoding}, tag=#{tag}" )
118
+ end
119
+
120
+ # Add the identifier bits into the object if it's a String or an Array.
121
+ # We can't add extra stuff to Fixnums and booleans, not that it makes much sense anyway.
122
+ obj and ([String,Array].include? obj.class) and obj.instance_eval "def ber_identifier; #{id}; end"
123
+ obj
124
+
125
+ end
126
+
127
+ end # module BERParser
128
+ end # module BER
129
+
130
+ end # module Net
131
+
132
+
133
+ class IO
134
+ include Net::BER::BERParser
135
+ end
136
+
137
+ require "stringio"
138
+ class StringIO
139
+ include Net::BER::BERParser
140
+ end
141
+
142
+
143
+ class String
144
+ def read_ber syntax=nil
145
+ StringIO.new(self).read_ber(syntax)
146
+ end
147
+ end
148
+
149
+
150
+
151
+ #----------------------------------------------
152
+
153
+
154
+ class FalseClass
155
+ #
156
+ # to_ber
157
+ #
158
+ def to_ber
159
+ "\001\001\000"
160
+ end
161
+ end
162
+
163
+
164
+ class TrueClass
165
+ #
166
+ # to_ber
167
+ #
168
+ def to_ber
169
+ "\001\001\001"
170
+ end
171
+ end
172
+
173
+
174
+
175
+ class Fixnum
176
+ #
177
+ # to_ber
178
+ #
179
+ def to_ber
180
+ i = [self].pack('w')
181
+ [2, i.length].pack("CC") + i
182
+ end
183
+
184
+ #
185
+ # to_ber_enumerated
186
+ #
187
+ def to_ber_enumerated
188
+ i = [self].pack('w')
189
+ [10, i.length].pack("CC") + i
190
+ end
191
+
192
+ #
193
+ # to_ber_length_encoding
194
+ #
195
+ def to_ber_length_encoding
196
+ if self <= 127
197
+ [self].pack('C')
198
+ else
199
+ i = [self].pack('N').sub(/^[\0]+/,"")
200
+ [0x80 + i.length].pack('C') + i
201
+ end
202
+ end
203
+
204
+ end # class Fixnum
205
+
206
+
207
+ class Bignum
208
+
209
+ def to_ber
210
+ i = [self].pack('w')
211
+ i.length > 126 and raise Net::BER::BerError.new( "range error in bignum" )
212
+ [2, i.length].pack("CC") + i
213
+ end
214
+
215
+ end
216
+
217
+
218
+
219
+ class String
220
+ #
221
+ # to_ber
222
+ # A universal octet-string is tag number 4,
223
+ # but others are possible depending on the context, so we
224
+ # let the caller give us one.
225
+ # The preferred way to do this in user code is via to_ber_application_sring
226
+ # and to_ber_contextspecific.
227
+ #
228
+ def to_ber code = 4
229
+ [code].pack('C') + length.to_ber_length_encoding + self
230
+ end
231
+
232
+ #
233
+ # to_ber_application_string
234
+ #
235
+ def to_ber_application_string code
236
+ to_ber( 0x40 + code )
237
+ end
238
+
239
+ #
240
+ # to_ber_contextspecific
241
+ #
242
+ def to_ber_contextspecific code
243
+ to_ber( 0x80 + code )
244
+ end
245
+
246
+ end # class String
247
+
248
+
249
+
250
+ class Array
251
+ #
252
+ # to_ber_appsequence
253
+ # An application-specific sequence usually gets assigned
254
+ # a tag that is meaningful to the particular protocol being used.
255
+ # This is different from the universal sequence, which usually
256
+ # gets a tag value of 16.
257
+ # Now here's an interesting thing: We're adding the X.690
258
+ # "application constructed" code at the top of the tag byte (0x60),
259
+ # but some clients, notably ldapsearch, send "context-specific
260
+ # constructed" (0xA0). The latter would appear to violate RFC-1777,
261
+ # but what do I know? We may need to change this.
262
+ #
263
+
264
+ def to_ber id = 0; to_ber_seq_internal( 0x30 + id ); end
265
+ def to_ber_set id = 0; to_ber_seq_internal( 0x31 + id ); end
266
+ def to_ber_sequence id = 0; to_ber_seq_internal( 0x30 + id ); end
267
+ def to_ber_appsequence id = 0; to_ber_seq_internal( 0x60 + id ); end
268
+ def to_ber_contextspecific id = 0; to_ber_seq_internal( 0xA0 + id ); end
269
+
270
+ private
271
+ def to_ber_seq_internal code
272
+ s = self.to_s
273
+ [code].pack('C') + s.length.to_ber_length_encoding + s
274
+ end
275
+
276
+ end # class Array
277
+
278
+