Reference · reference
encoding module
use encoding converts between strings, bytes and base64. Bytes are a List[int], the same representation fs::read_bytes returns and fs::write_bytes takes, so the two modules compose. A function that takes bytes returns Err when any element lies outside 0..=255.
base64_encode and base64_decode
base64_encode
base64_decode
Both use the standard base64 alphabet with = padding. base64_decode ignores leading and trailing whitespace and returns Err for any other character outside the alphabet.
utf8 and from_utf8
utf8
from_utf8
utf8 returns a string's UTF-8 bytes. from_utf8 decodes bytes into a string and returns Err when they are not valid UTF-8. To base64 a string, encode it to bytes first.
utf16le and from_utf16le
utf16le
from_utf16le
utf16le returns a string's UTF-16 little-endian bytes, with no byte order mark. Windows APIs and file formats that store wide strings use this form.
from_utf16le decodes UTF-16 little-endian bytes into a string. It strips a leading byte order mark (FF FE) if one is present. It returns Err when the byte count is odd or the bytes contain an unpaired surrogate; it does not replace bad input with U+FFFD.
A Windows unattend file hides a password as base64(UTF-16LE(password + suffix)), where the suffix is the element name, such as Password or AdministratorPassword:
use encoding
let hidden = base64_encode?
// write it with <PlainText>false</PlainText>