Class: Rex::Proto::LDAP::DnBinary
- Inherits:
-
Object
- Object
- Rex::Proto::LDAP::DnBinary
- Defined in:
- lib/rex/proto/ldap/dn_binary.rb
Overview
Handle converting objects into the DN-Binary syntax See: learn.microsoft.com/en-us/windows/win32/adschema/s-object-dn-binary
Instance Attribute Summary collapse
-
#data ⇒ Object
Raw bytes.
-
#dn ⇒ Object
LDAP Distinguished name.
Class Method Summary collapse
-
.decode(str) ⇒ Object
Turn a DN-Binary string into a structured object containing data and a DN.
Instance Method Summary collapse
-
#encode ⇒ String
Turn this structured object containing data and a DN into a DN-Binary string.
-
#initialize(dn, data) ⇒ DnBinary
constructor
A new instance of DnBinary.
Constructor Details
#initialize(dn, data) ⇒ DnBinary
Returns a new instance of DnBinary.
8 9 10 11 |
# File 'lib/rex/proto/ldap/dn_binary.rb', line 8 def initialize(dn, data) self.dn = dn self.data = data end |
Instance Attribute Details
#data ⇒ Object
Raw bytes
33 34 35 |
# File 'lib/rex/proto/ldap/dn_binary.rb', line 33 def data @data end |
#dn ⇒ Object
LDAP Distinguished name
34 35 36 |
# File 'lib/rex/proto/ldap/dn_binary.rb', line 34 def dn @dn end |
Class Method Details
.decode(str) ⇒ Object
Turn a DN-Binary string into a structured object containing data and a DN
15 16 17 18 19 20 21 22 23 |
# File 'lib/rex/proto/ldap/dn_binary.rb', line 15 def self.decode(str) groups = str.match(/B:(\d+):(([a-fA-F0-9]{2})*):(.*)/) raise ArgumentError.new('Invalid DN Binary string') if groups.nil? length = groups[1].to_i raise ArgumentError.new('Invalid DN Binary string length') if groups[2].length != length data = [groups[2]].pack('H*') DnBinary.new(groups[4], data) end |
Instance Method Details
#encode ⇒ String
Turn this structured object containing data and a DN into a DN-Binary string
27 28 29 30 31 |
# File 'lib/rex/proto/ldap/dn_binary.rb', line 27 def encode data_hex = self.data.unpack('H*')[0] "B:#{data_hex.length}:#{data_hex}:#{self.dn}" end |