net-ldap 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of net-ldap might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.rdoc +4 -0
- data/lib/net/ber/ber_parser.rb +12 -3
- data/lib/net/ber/core_ext.rb +3 -10
- data/lib/net/ber/core_ext/integer.rb +74 -0
- data/lib/net/ldap/version.rb +1 -1
- data/test/ber/test_ber.rb +27 -8
- metadata +3 -4
- data/lib/net/ber/core_ext/bignum.rb +0 -22
- data/lib/net/ber/core_ext/fixnum.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe93b5d4adc9f8aad092d00b1e3b6f9049ebf40d
|
4
|
+
data.tar.gz: 3483c7b26e26a6f87385e60f2c58b32fa508df89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4790e354827d3886500a788a154247c8b8ef582273e74d876d88d1a52edcfe5fb44c8f5efcbc54a7f246bca20413ace95491508f69d379c89b57b52c12b2f3f7
|
7
|
+
data.tar.gz: cab9f575616ca54675015d42ac15f4add481a24fd4ae5c30867980ddf306363dbb28262b134e04cbb975557a6821f777c2a62ee0aa4d1c0173991f8f62a28bea
|
data/History.rdoc
CHANGED
data/lib/net/ber/ber_parser.rb
CHANGED
@@ -41,9 +41,18 @@ module Net::BER::BERParser
|
|
41
41
|
s.ber_identifier = id
|
42
42
|
s
|
43
43
|
elsif object_type == :integer
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
neg = !(data.unpack("C").first & 0x80).zero?
|
45
|
+
int = 0
|
46
|
+
|
47
|
+
data.each_byte do |b|
|
48
|
+
int = (int << 8) + (neg ? 255 - b : b)
|
49
|
+
end
|
50
|
+
|
51
|
+
if neg
|
52
|
+
(int + 1) * -1
|
53
|
+
else
|
54
|
+
int
|
55
|
+
end
|
47
56
|
elsif object_type == :oid
|
48
57
|
# See X.690 pgh 8.19 for an explanation of this algorithm.
|
49
58
|
# This is potentially not good enough. We may need a
|
data/lib/net/ber/core_ext.rb
CHANGED
@@ -33,17 +33,10 @@ class Array
|
|
33
33
|
end
|
34
34
|
# :startdoc:
|
35
35
|
|
36
|
-
require 'net/ber/core_ext/
|
36
|
+
require 'net/ber/core_ext/integer'
|
37
37
|
# :stopdoc:
|
38
|
-
class
|
39
|
-
include Net::BER::Extensions::
|
40
|
-
end
|
41
|
-
# :startdoc:
|
42
|
-
|
43
|
-
require 'net/ber/core_ext/fixnum'
|
44
|
-
# :stopdoc:
|
45
|
-
class Fixnum
|
46
|
-
include Net::BER::Extensions::Fixnum
|
38
|
+
class Integer
|
39
|
+
include Net::BER::Extensions::Integer
|
47
40
|
end
|
48
41
|
# :startdoc:
|
49
42
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
##
|
3
|
+
# BER extensions to the Integer class, affecting Fixnum and Bignum objects.
|
4
|
+
module Net::BER::Extensions::Integer
|
5
|
+
##
|
6
|
+
# Converts the Integer to BER format.
|
7
|
+
def to_ber
|
8
|
+
"\002#{to_ber_internal}"
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Converts the Integer to BER enumerated format.
|
13
|
+
def to_ber_enumerated
|
14
|
+
"\012#{to_ber_internal}"
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Converts the Integer to BER length encoding format.
|
19
|
+
def to_ber_length_encoding
|
20
|
+
if self <= 127
|
21
|
+
[self].pack('C')
|
22
|
+
else
|
23
|
+
i = [self].pack('N').sub(/^[\0]+/,"")
|
24
|
+
[0x80 + i.length].pack('C') + i
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Generate a BER-encoding for an application-defined INTEGER. Examples of
|
30
|
+
# such integers are SNMP's Counter, Gauge, and TimeTick types.
|
31
|
+
def to_ber_application(tag)
|
32
|
+
[0x40 + tag].pack("C") + to_ber_internal
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Used to BER-encode the length and content bytes of an Integer. Callers
|
37
|
+
# must prepend the tag byte for the contained value.
|
38
|
+
def to_ber_internal
|
39
|
+
# Compute the byte length, accounting for negative values requiring two's
|
40
|
+
# complement.
|
41
|
+
size = 1
|
42
|
+
size += 1 until (((self < 0) ? ~self : self) >> (size * 8)).zero?
|
43
|
+
|
44
|
+
# Padding for positive, negative values. See section 8.5 of ITU-T X.690:
|
45
|
+
# http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
|
46
|
+
|
47
|
+
# For positive integers, if most significant bit in an octet is set to one,
|
48
|
+
# pad the result (otherwise it's decoded as a negative value).
|
49
|
+
if self > 0 && (self & (0x80 << (size - 1) * 8)) > 0
|
50
|
+
size += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
# And for negative integers, pad if the most significant bit in the octet
|
54
|
+
# is not set to one (othwerise, it's decoded as positive value).
|
55
|
+
if self < 0 && (self & (0x80 << (size - 1) * 8)) == 0
|
56
|
+
size += 1
|
57
|
+
end
|
58
|
+
|
59
|
+
# Store the size of the Integer in the result
|
60
|
+
result = [size]
|
61
|
+
|
62
|
+
# Appends bytes to result, starting with higher orders first. Extraction
|
63
|
+
# of bytes is done by right shifting the original Integer by an amount
|
64
|
+
# and then masking that with 0xff.
|
65
|
+
while size > 0
|
66
|
+
# right shift size - 1 bytes, mask with 0xff
|
67
|
+
result << ((self >> ((size - 1) * 8)) & 0xff)
|
68
|
+
size -= 1
|
69
|
+
end
|
70
|
+
|
71
|
+
result.pack('C*')
|
72
|
+
end
|
73
|
+
private :to_ber_internal
|
74
|
+
end
|
data/lib/net/ldap/version.rb
CHANGED
data/test/ber/test_ber.rb
CHANGED
@@ -26,25 +26,44 @@ class TestBEREncoding < Test::Unit::TestCase
|
|
26
26
|
0 => "\x02\x01\x00",
|
27
27
|
1 => "\x02\x01\x01",
|
28
28
|
127 => "\x02\x01\x7F",
|
29
|
-
128 => "\x02\
|
30
|
-
255 => "\x02\
|
29
|
+
128 => "\x02\x02\x00\x80",
|
30
|
+
255 => "\x02\x02\x00\xFF",
|
31
31
|
256 => "\x02\x02\x01\x00",
|
32
|
-
65535 => "\x02\
|
32
|
+
65535 => "\x02\x03\x00\xFF\xFF",
|
33
33
|
65536 => "\x02\x03\x01\x00\x00",
|
34
|
-
|
34
|
+
8388607 => "\x02\x03\x7F\xFF\xFF",
|
35
|
+
8388608 => "\x02\x04\x00\x80\x00\x00",
|
36
|
+
16_777_215 => "\x02\x04\x00\xFF\xFF\xFF",
|
35
37
|
0x01000000 => "\x02\x04\x01\x00\x00\x00",
|
36
38
|
0x3FFFFFFF => "\x02\x04\x3F\xFF\xFF\xFF",
|
37
39
|
0x4FFFFFFF => "\x02\x04\x4F\xFF\xFF\xFF",
|
38
40
|
|
39
41
|
# Some odd samples...
|
40
|
-
5 => "\
|
41
|
-
500 => "\
|
42
|
-
50_000 => "\x02\
|
43
|
-
5_000_000_000
|
42
|
+
5 => "\x02\x01\x05",
|
43
|
+
500 => "\x02\x02\x01\xf4",
|
44
|
+
50_000 => "\x02\x03\x00\xC3\x50",
|
45
|
+
5_000_000_000 => "\x02\x05\x01\x2a\x05\xF2\x00",
|
46
|
+
|
47
|
+
# negatives
|
48
|
+
-1 => "\x02\x01\xFF",
|
49
|
+
-127 => "\x02\x01\x81",
|
50
|
+
-128 => "\x02\x01\x80",
|
51
|
+
-255 => "\x02\x02\xFF\x01",
|
52
|
+
-256 => "\x02\x02\xFF\x00",
|
53
|
+
-65535 => "\x02\x03\xFF\x00\x01",
|
54
|
+
-65536 => "\x02\x03\xFF\x00\x00",
|
55
|
+
-65537 => "\x02\x03\xFE\xFF\xFF",
|
56
|
+
-8388607 => "\x02\x03\x80\x00\x01",
|
57
|
+
-8388608 => "\x02\x03\x80\x00\x00",
|
58
|
+
-16_777_215 => "\x02\x04\xFF\x00\x00\x01",
|
44
59
|
}.each do |number, expected_encoding|
|
45
60
|
define_method "test_encode_#{number}" do
|
46
61
|
assert_equal expected_encoding.b, number.to_ber
|
47
62
|
end
|
63
|
+
|
64
|
+
define_method "test_decode_encoded_#{number}" do
|
65
|
+
assert_equal number, expected_encoding.b.read_ber
|
66
|
+
end
|
48
67
|
end
|
49
68
|
|
50
69
|
# Round-trip encoding: This is mostly to be sure to cover Bignums well.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Cianfrocca
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2014-12-
|
16
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: flexmock
|
@@ -85,9 +85,8 @@ files:
|
|
85
85
|
- lib/net/ber/ber_parser.rb
|
86
86
|
- lib/net/ber/core_ext.rb
|
87
87
|
- lib/net/ber/core_ext/array.rb
|
88
|
-
- lib/net/ber/core_ext/bignum.rb
|
89
88
|
- lib/net/ber/core_ext/false_class.rb
|
90
|
-
- lib/net/ber/core_ext/
|
89
|
+
- lib/net/ber/core_ext/integer.rb
|
91
90
|
- lib/net/ber/core_ext/string.rb
|
92
91
|
- lib/net/ber/core_ext/true_class.rb
|
93
92
|
- lib/net/ldap.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# -*- ruby encoding: utf-8 -*-
|
2
|
-
##
|
3
|
-
# BER extensions to the Bignum class.
|
4
|
-
module Net::BER::Extensions::Bignum
|
5
|
-
##
|
6
|
-
# Converts a Bignum to an uncompressed BER integer.
|
7
|
-
def to_ber
|
8
|
-
result = []
|
9
|
-
|
10
|
-
# NOTE: Array#pack's 'w' is a BER _compressed_ integer. We need
|
11
|
-
# uncompressed BER integers, so we're not using that. See also:
|
12
|
-
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/228864
|
13
|
-
n = self
|
14
|
-
while n > 0
|
15
|
-
b = n & 0xff
|
16
|
-
result << b
|
17
|
-
n = n >> 8
|
18
|
-
end
|
19
|
-
|
20
|
-
"\002" + ([result.size] + result.reverse).pack('C*')
|
21
|
-
end
|
22
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# -*- ruby encoding: utf-8 -*-
|
2
|
-
##
|
3
|
-
# Ber extensions to the Fixnum class.
|
4
|
-
module Net::BER::Extensions::Fixnum
|
5
|
-
##
|
6
|
-
# Converts the fixnum to BER format.
|
7
|
-
def to_ber
|
8
|
-
"\002#{to_ber_internal}"
|
9
|
-
end
|
10
|
-
|
11
|
-
##
|
12
|
-
# Converts the fixnum to BER enumerated format.
|
13
|
-
def to_ber_enumerated
|
14
|
-
"\012#{to_ber_internal}"
|
15
|
-
end
|
16
|
-
|
17
|
-
##
|
18
|
-
# Converts the fixnum to BER length encodining format.
|
19
|
-
def to_ber_length_encoding
|
20
|
-
if self <= 127
|
21
|
-
[self].pack('C')
|
22
|
-
else
|
23
|
-
i = [self].pack('N').sub(/^[\0]+/,"")
|
24
|
-
[0x80 + i.length].pack('C') + i
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Generate a BER-encoding for an application-defined INTEGER. Examples of
|
30
|
-
# such integers are SNMP's Counter, Gauge, and TimeTick types.
|
31
|
-
def to_ber_application(tag)
|
32
|
-
[0x40 + tag].pack("C") + to_ber_internal
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Used to BER-encode the length and content bytes of a Fixnum. Callers
|
37
|
-
# must prepend the tag byte for the contained value.
|
38
|
-
def to_ber_internal
|
39
|
-
# CAUTION: Bit twiddling ahead. You might want to shield your eyes or
|
40
|
-
# something.
|
41
|
-
|
42
|
-
# Looks for the first byte in the fixnum that is not all zeroes. It does
|
43
|
-
# this by masking one byte after another, checking the result for bits
|
44
|
-
# that are left on.
|
45
|
-
size = Net::BER::MAX_FIXNUM_SIZE
|
46
|
-
while size > 1
|
47
|
-
break if (self & (0xff << (size - 1) * 8)) > 0
|
48
|
-
size -= 1
|
49
|
-
end
|
50
|
-
|
51
|
-
# Store the size of the fixnum in the result
|
52
|
-
result = [size]
|
53
|
-
|
54
|
-
# Appends bytes to result, starting with higher orders first. Extraction
|
55
|
-
# of bytes is done by right shifting the original fixnum by an amount
|
56
|
-
# and then masking that with 0xff.
|
57
|
-
while size > 0
|
58
|
-
# right shift size - 1 bytes, mask with 0xff
|
59
|
-
result << ((self >> ((size - 1) * 8)) & 0xff)
|
60
|
-
size -= 1
|
61
|
-
end
|
62
|
-
|
63
|
-
result.pack('C*')
|
64
|
-
end
|
65
|
-
private :to_ber_internal
|
66
|
-
end
|