Class: Net::NTLM::EncodeUtil
- Inherits:
-
Object
- Object
- Net::NTLM::EncodeUtil
- Defined in:
- lib/net/ntlm.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
104 105 106 |
# File 'lib/net/ntlm.rb', line 104 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
110 111 112 |
# File 'lib/net/ntlm.rb', line 110 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
116 117 118 |
# File 'lib/net/ntlm.rb', line 116 def self.swap16(str) str.unpack("v*").pack("n*") end |