2004-11-05 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 5 Nov 2004 17:19:09 +0000 (17:19 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 5 Nov 2004 17:19:09 +0000 (17:19 -0000)
* PrivateKeyTest.cs: Fixed SaltWithoutPassword test to always use
little endian.

svn path=/trunk/mcs/; revision=35705

mcs/class/Mono.Security/Test/Mono.Security.Authenticode/ChangeLog
mcs/class/Mono.Security/Test/Mono.Security.Authenticode/PrivateKeyTest.cs

index f399e7b2993bd36569bf39c80df6f7233cdba7b8..edd24086b5bfe67d551d1ef61ebabb02128c86db 100644 (file)
@@ -1,3 +1,8 @@
+2004-11-05  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * PrivateKeyTest.cs: Fixed SaltWithoutPassword test to always use 
+       little endian.
+
 2004-10-28  Sebastien Pouliot  <sebastien@ximian.com>
 
        * AuthenticodeDeformatterTest.cs: Check timestamp as an UTC value so 
index 671dc024c4eabeb20210822115737de31c58c6ec..ee8145cff6b7cc28d86819aec04382807e114bfc 100644 (file)
@@ -3,6 +3,7 @@
 //
 // Author:
 //     Sebastien Pouliot (sebastien@ximian.com)
+//     Bernie Solomon
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
 // Copyright (C) 2004 Novell (http://www.novell.com)
@@ -18,6 +19,51 @@ using NUnit.Framework;
 
 namespace MonoTests.Mono.Security.Authenticode {
 
+       // partial copy of /mcs/class/Mono.Security/Mono.Security/BitConverterLE.cs
+       internal sealed class BitConverterLE {
+
+               private BitConverterLE ()
+               {
+               }
+
+               unsafe private static byte[] GetUIntBytes (byte *bytes)
+               {
+                       if (BitConverter.IsLittleEndian)
+                               return new byte [] { bytes [0], bytes [1], bytes [2], bytes [3] };
+                       else
+                               return new byte [] { bytes [3], bytes [2], bytes [1], bytes [0] };
+               }
+
+               unsafe internal static byte[] GetBytes (int value)
+               {
+                       return GetUIntBytes ((byte *) &value);
+               }
+
+               unsafe private static void UIntFromBytes (byte *dst, byte[] src, int startIndex)
+               {
+                       if (BitConverter.IsLittleEndian) {
+                               dst [0] = src [startIndex];
+                               dst [1] = src [startIndex + 1];
+                               dst [2] = src [startIndex + 2];
+                               dst [3] = src [startIndex + 3];
+                       } else {
+                               dst [0] = src [startIndex + 3];
+                               dst [1] = src [startIndex + 2];
+                               dst [2] = src [startIndex + 1];
+                               dst [3] = src [startIndex];
+                       }
+               }
+
+               unsafe internal static int ToInt32 (byte[] value, int startIndex)
+               {
+                       int ret;
+
+                       UIntFromBytes ((byte *) &ret, value, startIndex);
+
+                       return ret;
+               }
+       }
+
 // HOWTO create a PVK file (on Windows using MS tools)
 // makecert -n "CN=PVK1" -sv 1.pvk 1.cer
 
@@ -249,15 +295,15 @@ public class PrivateKeyTest : Assertion {
        public void SaltWithoutPassword () 
        {
                byte[] bad = (byte[]) nopwd.Clone ();
-               int saltlen = BitConverter.ToInt32 (bad, 16);
-               int keylen = BitConverter.ToInt32 (bad, 20);
+               int saltlen = BitConverterLE.ToInt32 (bad, 16);
+               int keylen = BitConverterLE.ToInt32 (bad, 20);
                // preserve total length
                saltlen += 8;
                keylen -= 8;
                // modify blob
-               byte[] data = BitConverter.GetBytes (saltlen);
+               byte[] data = BitConverterLE.GetBytes (saltlen);
                Buffer.BlockCopy (data, 0, bad, 16, data.Length); 
-               data = BitConverter.GetBytes (keylen);
+               data = BitConverterLE.GetBytes (keylen);
                Buffer.BlockCopy (data, 0, bad, 20, data.Length); 
                // save-n-load          
                WriteBuffer (bad);