Module: Net::BER::Extensions::String
- Defined in:
- lib/adauth/net-ldap/string.rb
Overview
BER extensions to the String class.
Instance Method Summary collapse
-
#read_ber(syntax = nil) ⇒ Object
Nondestructively reads a BER object from this string.
-
#read_ber!(syntax = nil) ⇒ Object
Destructively reads a BER object from the string.
-
#reject_empty_ber_arrays ⇒ Object
Removes empty blocks from arrays.
-
#to_ber(code = 0x04) ⇒ Object
Converts a string to a BER string.
-
#to_ber_application_string(code) ⇒ Object
Creates an application-specific BER string encoded value with the provided syntax code value.
-
#to_ber_contextspecific(code) ⇒ Object
Creates a context-specific BER string encoded value with the provided syntax code value.
Instance Method Details
#read_ber(syntax = nil) ⇒ Object
Nondestructively reads a BER object from this string.
52 53 54 |
# File 'lib/adauth/net-ldap/string.rb', line 52 def read_ber(syntax = nil) StringIO.new(self).read_ber(syntax) end |
#read_ber!(syntax = nil) ⇒ Object
Destructively reads a BER object from the string.
58 59 60 61 62 63 64 65 |
# File 'lib/adauth/net-ldap/string.rb', line 58 def read_ber!(syntax = nil) io = StringIO.new(self) result = io.read_ber(syntax) self.slice!(0...io.pos) return result end |
#reject_empty_ber_arrays ⇒ Object
Removes empty blocks from arrays
68 69 70 |
# File 'lib/adauth/net-ldap/string.rb', line 68 def reject_empty_ber_arrays self.gsub(/0\000/n,'') end |
#to_ber(code = 0x04) ⇒ Object
Converts a string to a BER string. Universal octet-strings are tagged with 0x04, but other values are possible depending on the context, so we let the caller give us one.
User code should call either #to_ber_application_string or #to_ber_contextspecific.
18 19 20 21 |
# File 'lib/adauth/net-ldap/string.rb', line 18 def to_ber(code = 0x04) raw_string = raw_utf8_encoded [code].pack('C') + raw_string.length.to_ber_length_encoding + raw_string end |
#to_ber_application_string(code) ⇒ Object
Creates an application-specific BER string encoded value with the provided syntax code value.
39 40 41 |
# File 'lib/adauth/net-ldap/string.rb', line 39 def to_ber_application_string(code) to_ber(0x40 + code) end |
#to_ber_contextspecific(code) ⇒ Object
Creates a context-specific BER string encoded value with the provided syntax code value.
46 47 48 |
# File 'lib/adauth/net-ldap/string.rb', line 46 def to_ber_contextspecific(code) to_ber(0x80 + code) end |