ruby-ldap/ruby-net-ldap — Issue #31: Proper BER value for "true"
Author: MikeWillCook
Created: 2012-02-21 22:56:06+00:00
State: open

I think I have an answer to AZ's code comment on the "true" value BER encoding...

According to RFC2251, section 5.1(3), it looks like "true" should be an 0xFF instead of 1:

(3) If the value of a BOOLEAN type is true, the encoding MUST have its contents octets set to hex "FF".

I've confirmed this matches other LDAP client protocol communications. However, since the default string encoding is UTF-8 it has potential to cause an encoding exception on the array join, so I think it should also be forced to ASCII-8BIT to prevent problems.

So, here's a couple tiny patches with relevant changes for consideration (including 8BIT'ing the "false" string):

--- lib/net/ber/core_ext/true_class.rb
+++ lib/net/ber/core_ext/true_class.rb
@@ -5,8 +5,6 @@ module Net::BER::Extensions::TrueClass
##
# Converts +true+ to the BER wireline representation of +true+.
def to_ber
- # 20100319 AZ: Note that this may not be the completely correct value,
- # per some test documentation. We need to determine the truth of this.
- "\001\001\001"
+ "\x01\x01\xFF".force_encoding("ASCII-8BIT")
end
end

--- lib/net/ber/core_ext/false_class.rb
+++ lib/net/ber/core_ext/false_class.rb
@@ -5,6 +5,6 @@ module Net::BER::Extensions::FalseClass
##
# Converts +false+ to the BER wireline representation of +false+.
def to_ber
- "\001\001\000"
+ "\x01\x01\x00".force_encoding("ASCII-8BIT")
end
end