Class: Net::NTLM::EncodeUtil
- Inherits:
-
Object
- Object
- Net::NTLM::EncodeUtil
- Defined in:
- lib/net/ntlm/encode_util.rb
Class Method Summary collapse
-
.decode_utf16le(str) ⇒ Object
Decode a UTF16 string to a ASCII string.
-
.encode_utf16le(str) ⇒ Object
Encodes a ASCII string to a UTF16 string.
-
.swap16(str) ⇒ Object
Taggle the strings endianness between big/little and little/big.
Class Method Details
.decode_utf16le(str) ⇒ Object
Decode a UTF16 string to a ASCII string
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
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
22 23 24 |
# File 'lib/net/ntlm/encode_util.rb', line 22 def self.swap16(str) str.unpack("v*").pack("n*") end |