! Fixes all tests
Some code has been removed. Version control is not synonymous with code storage - if you're not using it now, you probably don't have working tests and the code will be buggy anyway. Write it when you need it.
This commit is contained in:
parent
75f37c58b9
commit
1509aa8ef6
16 changed files with 164 additions and 166 deletions
|
@ -10,8 +10,8 @@ class Array
|
|||
end
|
||||
|
||||
class String
|
||||
include Net::LDAP::Extensions::String
|
||||
include Net::BER::BERParser
|
||||
include Net::LDAP::Extensions::String
|
||||
end
|
||||
|
||||
class Bignum
|
||||
|
@ -40,4 +40,4 @@ end
|
|||
|
||||
class OpenSSL::SSL::SSLSocket
|
||||
include Net::BER::BERParser
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ module Net
|
|||
|
||||
private
|
||||
def to_ber_seq_internal code
|
||||
s = self.to_s
|
||||
s = self.join
|
||||
[code].pack('C') + s.length.to_ber_length_encoding + s
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,32 +4,19 @@ module Net
|
|||
module Bignum
|
||||
|
||||
def to_ber
|
||||
#i = [self].pack('w')
|
||||
#i.length > 126 and raise Net::BER::BerError.new( "range error in bignum" )
|
||||
#[2, i.length].pack("CC") + i
|
||||
# NOTE: Array#pack's 'w' is a BER _compressed_ integer. We need uncompressed
|
||||
# BER integers, so we're not using that.
|
||||
# See also: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/228864
|
||||
result = []
|
||||
|
||||
# Ruby represents Bignums as two's-complement numbers so we may actually be
|
||||
# good as far as representing negatives goes.
|
||||
# I'm sure this implementation can be improved performance-wise if necessary.
|
||||
# Ruby's Bignum#size returns the number of bytes in the internal representation
|
||||
# of the number, but it can and will include leading zero bytes on at least
|
||||
# some implementations. Evidently Ruby stores these as sets of quadbytes.
|
||||
# It's not illegal in BER to encode all of the leading zeroes but let's strip
|
||||
# them out anyway.
|
||||
#
|
||||
sz = self.size
|
||||
out = "\000" * sz
|
||||
(sz*8).times {|bit|
|
||||
if self[bit] == 1
|
||||
out[bit/8] += (1 << (bit % 8))
|
||||
end
|
||||
}
|
||||
|
||||
while out.length > 1 and out[-1] == 0
|
||||
out.slice!(-1,1)
|
||||
n = self
|
||||
while n>0
|
||||
b = n & 0xff
|
||||
result << b
|
||||
n = n >> 8
|
||||
end
|
||||
|
||||
[2, out.length].pack("CC") + out.reverse
|
||||
"\002" + ([result.size] + result.reverse).pack('C*')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,14 +2,23 @@ module Net
|
|||
class LDAP
|
||||
module Extensions
|
||||
module Fixnum
|
||||
#
|
||||
# to_ber
|
||||
#
|
||||
def to_ber
|
||||
"\002" + to_ber_internal
|
||||
end
|
||||
|
||||
#
|
||||
# to_ber_enumerated
|
||||
#
|
||||
def to_ber_enumerated
|
||||
"\012" + to_ber_internal
|
||||
end
|
||||
|
||||
#
|
||||
# to_ber_length_encoding
|
||||
#
|
||||
def to_ber_length_encoding
|
||||
if self <= 127
|
||||
[self].pack('C')
|
||||
|
@ -29,21 +38,24 @@ module Net
|
|||
#--
|
||||
# Called internally to BER-encode the length and content bytes of a Fixnum.
|
||||
# The caller will prepend the tag byte.
|
||||
MAX_SIZE = 0.size
|
||||
def to_ber_internal
|
||||
# PLEASE optimize this code path. It's awfully ugly and probably slow.
|
||||
# It also doesn't understand negative numbers yet.
|
||||
raise Net::BER::BerError.new( "range error in fixnum" ) unless self >= 0
|
||||
z = [self].pack("N")
|
||||
zlen = if self < 0x80
|
||||
1
|
||||
elsif self < 0x8000
|
||||
2
|
||||
elsif self < 0x800000
|
||||
3
|
||||
else
|
||||
4
|
||||
size = MAX_SIZE
|
||||
while size>1
|
||||
break if (self & (0xff << (size-1)*8)) > 0
|
||||
size -= 1
|
||||
end
|
||||
[zlen].pack("C") + z[0-zlen,zlen]
|
||||
|
||||
result = [size]
|
||||
|
||||
while size>0
|
||||
# right shift size-1 bytes, mask with 0xff
|
||||
result << ((self >> ((size-1)*8)) & 0xff)
|
||||
|
||||
size -= 1
|
||||
end
|
||||
|
||||
result.pack('C*')
|
||||
end
|
||||
private :to_ber_internal
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'stringio'
|
||||
|
||||
module Net
|
||||
class LDAP
|
||||
module Extensions
|
||||
|
@ -29,18 +31,9 @@ module Net
|
|||
end
|
||||
|
||||
def read_ber syntax=nil
|
||||
StringIO.new(self).read_ber(syntax)
|
||||
StringIO.new(self).
|
||||
read_ber(syntax)
|
||||
end
|
||||
|
||||
# def read_ber! syntax=nil
|
||||
# obj,n_consumed = read_ber_from_string(self, syntax)
|
||||
# if n_consumed
|
||||
# self.slice!(0...n_consumed)
|
||||
# obj
|
||||
# else
|
||||
# nil
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
# $Id$
|
||||
#
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
|
@ -25,6 +20,7 @@
|
|||
#
|
||||
#
|
||||
|
||||
require 'strscan'
|
||||
|
||||
module Net
|
||||
class LDAP
|
||||
|
|
|
@ -43,7 +43,7 @@ module Net
|
|||
when :md5
|
||||
[Digest::MD5.new, 'MD5']
|
||||
when :sha
|
||||
[Digest::SHA1.new, 'sha']
|
||||
[Digest::SHA1.new, 'SHA']
|
||||
# when ssha
|
||||
else
|
||||
raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue