[Mono-dev] Endian Question
Neale Ferguson
neale at sinenomine.net
Tue Apr 28 18:40:47 UTC 2015
The following test fails on s390x as the string that is encoded from the
decrypted block ends is in little endian order:
public void FullRoundtripRead ()
{
byte[] encrypted;
using (DebugStream mem1 = new DebugStream ()) {
byte[] toEncrypt =
Encoding.Unicode.GetBytes ("Please encode me!");
using (CryptoStream crypt = new
CryptoStream (mem1, aes.CreateEncryptor (), CryptoStreamMode.Write)) {
crypt.Write (toEncrypt, 0,
toEncrypt.Length);
crypt.FlushFinalBlock ();
}
encrypted = mem1.ToArray ();
}
using (DebugStream mem2 = new DebugStream
(encrypted)) {
byte[] buffer = new byte [1024];
CryptoStream cr = new CryptoStream (mem2,
aes.CreateDecryptor (), CryptoStreamMode.Read);
int len = cr.Read (buffer, 0,
buffer.Length);
cr.Close ();
Assert.AreEqual (34, len, "Full Length
Read");
Assert.AreEqual ("Please encode me!",
Encoding.Unicode.GetString (buffer, 0, len), "Full Block Read");
}
}
The question is at what point should byte swapping be performed? Should
all Encoding.Unicode.GetBytes(string) do the swap to little ending and
Encoding.Unicode.GetString(bytes) do the reverse?
Neale
More information about the Mono-devel-list
mailing list