Module: Net::BER::Extensions::Array

Included in:
Array
Defined in:
lib/net/ber/core_ext/array.rb

Overview

BER extensions to the Array class.

Instance Method Summary collapse

Instance Method Details

#to_ber(id = 0) ⇒ Object Also known as: to_ber_sequence

Converts an Array to a BER sequence. All values in the Array are expected to be in BER format prior to calling this method.


8
9
10
11
12
# File 'lib/net/ber/core_ext/array.rb', line 8

def to_ber(id = 0)
  # The universal sequence tag 0x30 is composed of the base tag value
  # (0x10) and the constructed flag (0x20).
  to_ber_seq_internal(0x30 + id)
end

#to_ber_appsequence(id = 0) ⇒ Object

Converts an Array to an application-specific sequence, assigned a tag value that is meaningful to the particular protocol being used. All values in the Array are expected to be in BER format pr prior to calling this method. – Implementor's note 20100320(AZ): RFC 4511 (the LDAPv3 protocol) as well as earlier RFCs 1777 and 2559 seem to indicate that LDAP only has application constructed sequences (0x60). However, ldapsearch sends some context-specific constructed sequences (0xA0); other clients may do the same. This behaviour appears to violate the RFCs. In real-world practice, we may need to change calls of #to_ber_appsequence to #to_ber_contextspecific for full LDAP server compatibility.

This note probably belongs elsewhere. ++


40
41
42
43
44
# File 'lib/net/ber/core_ext/array.rb', line 40

def to_ber_appsequence(id = 0)
  # The application sequence tag always starts from the application flag
  # (0x40) and the constructed flag (0x20).
  to_ber_seq_internal(0x60 + id)
end

#to_ber_contextspecific(id = 0) ⇒ Object

Converts an Array to a context-specific sequence, assigned a tag value that is meaningful to the particular context of the particular protocol being used. All values in the Array are expected to be in BER format prior to calling this method.


51
52
53
54
55
# File 'lib/net/ber/core_ext/array.rb', line 51

def to_ber_contextspecific(id = 0)
  # The application sequence tag always starts from the context flag
  # (0x80) and the constructed flag (0x20).
  to_ber_seq_internal(0xa0 + id)
end

#to_ber_controlObject

Converts an array into a set of ber control codes The expected format is [[control_oid, criticality, control_value(optional)]]

[['1.2.840.113556.1.4.805',true]]

88
89
90
91
92
93
94
95
# File 'lib/net/ber/core_ext/array.rb', line 88

def to_ber_control
  #if our array does not contain at least one array then wrap it in an array before going forward
  ary = self[0].kind_of?(Array) ? self : [self]
  ary = ary.collect do |control_sequence|
    control_sequence.collect(&:to_ber).to_ber_sequence.reject_empty_ber_arrays
  end
  ary.to_ber_sequence.reject_empty_ber_arrays
end

#to_ber_oidObject

SNMP Object Identifiers (OID) are special arrays – 20100320 AZ: I do not think that this method should be in BER, since this appears to be SNMP-specific. This should probably be subsumed by a proper SNMP OID object. ++

Raises:


73
74
75
76
77
78
79
80
81
# File 'lib/net/ber/core_ext/array.rb', line 73

def to_ber_oid
  ary = self.dup
  first = ary.shift
  raise Net::BER::BerError, "Invalid OID" unless [0, 1, 2].include?(first)
  first = first * 40 + ary.shift
  ary.unshift first
  oid = ary.pack("w*")
  [6, oid.length].pack("CC") + oid
end

#to_ber_set(id = 0) ⇒ Object

Converts an Array to a BER set. All values in the Array are expected to be in BER format prior to calling this method.


18
19
20
21
22
# File 'lib/net/ber/core_ext/array.rb', line 18

def to_ber_set(id = 0)
  # The universal set tag 0x31 is composed of the base tag value (0x11)
  # and the constructed flag (0x20).
  to_ber_seq_internal(0x31 + id)
end