def parse_ber(ber)
case ber.ber_identifier
when 0xa0
ber.map { |b| parse_ber(b) }.inject { |memo, obj| memo & obj }
when 0xa1
ber.map { |b| parse_ber(b) }.inject { |memo, obj| memo | obj }
when 0xa2
~parse_ber(ber.first)
when 0xa3
if ber.last == "*"
else
eq(ber.first, ber.last)
end
when 0xa4
str = ""
final = false
ber.last.each { |b|
case b.ber_identifier
when 0x80
raise Net::LDAP::LdapError, "Unrecognized substring filter; bad initial value." if str.length > 0
str += b
when 0x81
str += "*#{b}"
when 0x82
str += "*#{b}"
final = true
end
}
str += "*" unless final
eq(ber.first.to_s, str)
when 0xa5
ge(ber.first.to_s, ber.last.to_s)
when 0xa6
le(ber.first.to_s, ber.last.to_s)
when 0x87
present?(ber.to_s)
when 0xa9
raise Net::LDAP::LdapError, "Invalid extensible search filter, should be at least two elements" if ber.size<2
type = value = dn = rule = nil
ber.each do |element|
case element.ber_identifier
when 0x81 then rule=element
when 0x82 then type=element
when 0x83 then value=element
when 0x84 then dn='dn'
end
end
attribute = ''
attribute << type if type
attribute << ":#{dn}" if dn
attribute << ":#{rule}" if rule
ex(attribute, value)
else
raise Net::LDAP::LdapError, "Invalid BER tag-value (#{ber.ber_identifier}) in search filter."
end
end