Method: Net::LDAP::PDU#initialize

Defined in:
lib/net/ldap/pdu.rb

#initialize(ber_object) ⇒ PDU

Messy. Does this functionality belong somewhere else?



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/net/ldap/pdu.rb', line 60

def initialize(ber_object)
  begin
    @message_id = ber_object[0].to_i
    # Grab the bottom five bits of the identifier so we know which type of
    # PDU this is.
    #
    # This is safe enough in LDAP-land, but it is recommended that other
    # approaches be taken for other protocols in the case that there's an
    # app-specific tag that has both primitive and constructed forms.
    @app_tag = ber_object[1].ber_identifier & 0x1f
    @ldap_controls = []
  rescue Exception => ex
    raise Net::LDAP::PDU::Error, "LDAP PDU Format Error: #{ex.message}"
  end

  case @app_tag
  when BindResult
    parse_bind_response(ber_object[1])
  when SearchReturnedData
    parse_search_return(ber_object[1])
  when SearchResultReferral
    parse_search_referral(ber_object[1])
  when SearchResult
    parse_ldap_result(ber_object[1])
  when ModifyResponse
    parse_ldap_result(ber_object[1])
  when AddResponse
    parse_ldap_result(ber_object[1])
  when DeleteResponse
    parse_ldap_result(ber_object[1])
  when ModifyRDNResponse
    parse_ldap_result(ber_object[1])
  when SearchRequest
    parse_ldap_search_request(ber_object[1])
  when BindRequest
    parse_bind_request(ber_object[1])
  when UnbindRequest
    parse_unbind_request(ber_object[1])
  when ExtendedResponse
    parse_ldap_result(ber_object[1])
  else
    raise LdapPduError.new("unknown pdu-type: #{@app_tag}")
  end

  parse_controls(ber_object[2]) if ber_object[2]
end