Class: Net::NTLM::EncodeUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ntlm/encode_util.rb

Class Method Summary collapse

Class Method Details

.decode_utf16le(str) ⇒ Object

Decode a UTF16 string to a ASCII string

Parameters:

  • str (String)

    The string to convert



10
11
12
# File 'lib/net/ntlm/encode_util.rb', line 10

def self.decode_utf16le(str)
  Kconv.kconv(swap16(str), Kconv::ASCII, Kconv::UTF16)
end

.encode_utf16le(str) ⇒ Object

Note:

This implementation may seem stupid but the problem is that UTF16-LE and UTF-8 are incompatiable encodings. This library uses string contatination to build the packet bytes. The end result is that you can either marshal the encodings elsewhere of simply know that each time you call encode_utf16le the function will convert the string bytes to UTF-16LE and note the encoding as UTF-8 so that byte concatination works seamlessly.

Encodes a ASCII string to a UTF16 string

Parameters:

  • str (String)

    The string to convert



16
17
18
# File 'lib/net/ntlm/encode_util.rb', line 16

def self.encode_utf16le(str)
  swap16(Kconv.kconv(str, Kconv::UTF16, Kconv::ASCII))
end

.swap16(str) ⇒ Object

Taggle the strings endianness between big/little and little/big

Parameters:

  • str (String)

    The string to swap the endianness on



22
23
24
# File 'lib/net/ntlm/encode_util.rb', line 22

def self.swap16(str)
  str.unpack("v*").pack("n*")
end