lib/net/ldap/filter.rb
##
# Converts an LDAP search filter in BER format to an Net::LDAP::Filter
# object. The incoming BER object most likely came to us by parsing an
# LDAP searchRequest PDU. See also the comments under #to_ber, including
# the grammar snippet from the RFC.
#--
# We're hardcoding the BER constants from the RFC. These should be
# broken out insto constants.
Converts an LDAP search filter in BER format to an Net::LDAP::Filter
object. The incoming BER object most likely came to us by parsing an
LDAP searchRequest PDU. See also the comments under #to_ber, including
the grammar snippet from the RFC.

We're hardcoding the BER constants from the RFC. These should be
broken out insto constants.
Converts an LDAP search filter in BER format to an Net :: LDAP :: Filter object . The incoming BER object most likely came to us by parsing an LDAP searchRequest PDU . See also the comments under #to_ber including the grammar snippet from the RFC . We ' re hardcoding the BER constants from the RFC . These should be broken out insto constants .
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 do |b|
          case b.ber_identifier
          when 0x80 
            raise Net::LDAP::SubstringFilterError, "Unrecognized substring filter; bad initial value." if str.length > 0
            str += escape(b)
          when 0x81 
            str += "*#{escape(b)}"
          when 0x82 
            str += "*#{escape(b)}"
            final = true
          end
        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::SearchFilterError, "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::BERInvalidError, "Invalid BER tag-value (#{ber.ber_identifier}) in search filter."
      end
    end
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 do | b | case b . ber_identifier when 0x80 raise Net :: LDAP :: SubstringFilterError , "Unrecognized substring filter; bad initial value." if str . length > 0 str += escape ( b ) when 0x81 str += "*#{escape(b)}" when 0x82 str += "*#{escape(b)}" final = true end 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 :: SearchFilterError , "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 :: BERInvalidError , "Invalid BER tag-value (#{ber.ber_identifier}) in search filter." end end
Converts an LDAP search filter in BER format to an Net::LDAP::Filter
object.
Converts an LDAP search filter in BER format to an Net :: LDAP :: Filter object .
# context-specific constructed 0, "and" # context-specific constructed 1, "or" # context-specific constructed 2, "not" # context-specific constructed 3, "equalityMatch" # context-specific constructed 4, "substring" # context-specific primitive 0, SubstringFilter "initial" # context-specific primitive 0, SubstringFilter "any" # context-specific primitive 0, SubstringFilter "final" # context-specific constructed 5, "greaterOrEqual" # context-specific constructed 6, "lessOrEqual" # context-specific primitive 7, "present" # call to_s to get rid of the BER-identifiedness of the incoming string. # context-specific constructed 9, "extensible comparison" # Reassembles the extensible filter parts # (["sn", "2.4.6.8.10", "Barbara Jones", '1'])
ber
<not_specific>