class ROM::LDAP::PDU

LDAP Message Protocol Data Unit (PDU)

@api private

Public Instance Methods

add_response?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 193
def add_response?
  pdu_type == :add_response
end
advice() click to toggle source

@example

"Matchingrule is required for sorting by the attribute cn"

@return [String]

# File lib/rom/ldap/pdu.rb, line 62
def advice
  tag[2]
end
app_tag() click to toggle source

@return [Integer]

# File lib/rom/ldap/pdu.rb, line 40
def app_tag
  tag.ber_identifier & 0x1f
end
bind_parameters() click to toggle source

@return [OpenStruct] => :version, :name, :authentication

# File lib/rom/ldap/pdu.rb, line 91
def bind_parameters
  return unless bind_request?

  s = ::OpenStruct.new
  s.version, s.name, s.authentication = tag
  s
end
bind_request?() click to toggle source

@see tools.ietf.org/html/rfc4511#section-4.2.1

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 201
def bind_request?
  pdu_type == :bind_request
end
bind_result() click to toggle source

@return [Array] => [version, username, password]

# File lib/rom/ldap/pdu.rb, line 81
def bind_result
  return unless bind_result?
  raise ResponseTypeInvalidError, 'Invalid bind_result' unless gteq_3?

  tag
end
bind_result?() click to toggle source

A successful operation is indicated by a BindResponse with a resultCode set to success.

@see tools.ietf.org/html/rfc4511#section-4.2.2

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 211
def bind_result?
  pdu_type.eql?(:bind_result)
end
error_message() click to toggle source

Grep for error message

@return [String, FalseClass]

# File lib/rom/ldap/pdu.rb, line 173
def error_message
  tag[3][/comment: (.*), data/, 1] if tag[3]
end
extended_response() click to toggle source

Message

@example => “No attribute with the name false exists in the server's schema”

@return [String, NilClass]

# File lib/rom/ldap/pdu.rb, line 123
def extended_response
  raise ResponseTypeInvalidError, 'Invalid extended_response' unless gteq_3?

  tag[3] if extended_response?
end
extended_response?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 235
def extended_response?
  pdu_type == :extended_response
end
failure?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 247
def failure?
  !success?
end
flag() click to toggle source

@return [String]

# File lib/rom/ldap/pdu.rb, line 185
def flag
  detailed_response[2]
end
info() click to toggle source

@return [String]

# File lib/rom/ldap/pdu.rb, line 179
def info
  detailed_response[1]
end
matched_dn() click to toggle source

@return [String]

# File lib/rom/ldap/pdu.rb, line 53
def matched_dn
  tag[1]
end
message() click to toggle source

First item from responses.yaml

@return [String]

# File lib/rom/ldap/pdu.rb, line 165
def message
  detailed_response[0]
end
pdu_type() click to toggle source

@return [Symbol]

# File lib/rom/ldap/pdu.rb, line 255
def pdu_type
  BER.fetch(:response, app_tag) || raise(ResponseTypeInvalidError, "Unknown pdu_type: #{app_tag}")
end
result_code() click to toggle source

@return [Integer]

# File lib/rom/ldap/pdu.rb, line 46
def result_code
  tag[0]
end
result_code_symbol() click to toggle source

@return [Symbol]

# File lib/rom/ldap/pdu.rb, line 261
def result_code_symbol
  BER.fetch(:result, result_code)
end
result_controls() click to toggle source

RFC-2251, an LDAP 'control' is a sequence of tuples, each consisting of

- an OID
- a boolean criticality flag defaulting FALSE
- and an optional Octet String

If only two fields are given, the second one may be either criticality or data, since criticality has a default value. RFC-2696 is a good example.

@see Connection::Read#search

@return [Array<OpenStruct>] => :oid, :criticality, :value

# File lib/rom/ldap/pdu.rb, line 151
def result_controls
  ctrls.map do |control|
    oid, level, value = control
    value, level = level, false if level.is_a?(String)
    ::OpenStruct.new(oid: oid, criticality: level, value: value)
  end
end
result_server_sasl_creds() click to toggle source
# File lib/rom/ldap/pdu.rb, line 72
def result_server_sasl_creds
  return unless bind_result? && gteq4?

  tag[3]
end
search_entry() click to toggle source
“dn”, [ entry… ]

@return [Array, NilClass]

# File lib/rom/ldap/pdu.rb, line 133
def search_entry
  raise ResponseTypeInvalidError, 'Invalid search_entry' unless gteq_2?

  tag if search_result?
end
search_parameters() click to toggle source

@return [OpenStruct, NilClass] => :version, :name, :authentication

# File lib/rom/ldap/pdu.rb, line 102
def search_parameters
  return unless search_request?

  s = ::OpenStruct.new
  s.base_object,
  s.scope,
  s.deref_aliases,
  s.size_limit,
  s.time_limit,
  s.types_only,
  s.filter,
  s.attributes = tag
  s
end
search_referral?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 229
def search_referral?
  pdu_type == :search_result_referral
end
search_referrals() click to toggle source
# File lib/rom/ldap/pdu.rb, line 66
def search_referrals
  return unless search_referral?

  tag[3] || EMPTY_ARRAY
end
search_request?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 217
def search_request?
  pdu_type.eql?(:search_request)
end
search_result?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 223
def search_result?
  pdu_type.eql?(:search_returned_data)
end
success?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 241
def success?
  SUCCESS_CODES.include?(result_code_symbol)
end

Private Instance Methods

detailed_response() click to toggle source
# File lib/rom/ldap/pdu.rb, line 267
def detailed_response
  RESPONSES[result_code_symbol]
end
gteq_2?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 273
def gteq_2?
  tag.length >= 2
end
gteq_3?() click to toggle source

@return [Boolean]

# File lib/rom/ldap/pdu.rb, line 279
def gteq_3?
  tag.length >= 3
end