2010-02-12 14:39:57 +01:00
|
|
|
require 'stringio'
|
|
|
|
|
2010-02-09 23:46:49 +01:00
|
|
|
module Net
|
|
|
|
class LDAP
|
|
|
|
module Extensions
|
|
|
|
module String
|
|
|
|
#
|
|
|
|
# to_ber
|
|
|
|
# A universal octet-string is tag number 4,
|
|
|
|
# but others are possible depending on the context, so we
|
|
|
|
# let the caller give us one.
|
|
|
|
# The preferred way to do this in user code is via to_ber_application_sring
|
|
|
|
# and to_ber_contextspecific.
|
|
|
|
#
|
|
|
|
def to_ber code = 4
|
|
|
|
[code].pack('C') + length.to_ber_length_encoding + self
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# to_ber_application_string
|
|
|
|
#
|
|
|
|
def to_ber_application_string code
|
|
|
|
to_ber( 0x40 + code )
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# to_ber_contextspecific
|
|
|
|
#
|
|
|
|
def to_ber_contextspecific code
|
|
|
|
to_ber( 0x80 + code )
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_ber syntax=nil
|
2010-02-12 14:39:57 +01:00
|
|
|
StringIO.new(self).
|
|
|
|
read_ber(syntax)
|
2010-02-09 23:46:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|