1 //
2 // MonoTests.System.Security.Cryptography.Xml.AssertCrypto.cs
3 //
4 // Author:
5 //	Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 
11 using System;
12 using System.Security.Cryptography;
13 
14 using NUnit.Framework;
15 
16 namespace MonoTests.System.Security.Cryptography.Xml {
17 
18 	public class AssertCrypto {
19 
20 		// because most crypto stuff works with byte[] buffers
AssertEquals(string msg, byte[] array1, byte[] array2)21 		static public void AssertEquals (string msg, byte[] array1, byte[] array2)
22 		{
23 			if ((array1 == null) && (array2 == null))
24 				return;
25 			if (array1 == null)
26 				Assert.Fail (msg + " -> First array is NULL");
27 			if (array2 == null)
28 				Assert.Fail (msg + " -> Second array is NULL");
29 
30 			bool a = (array1.Length == array2.Length);
31 			if (a) {
32 				for (int i = 0; i < array1.Length; i++) {
33 					if (array1 [i] != array2 [i]) {
34 						a = false;
35 						break;
36 					}
37 				}
38 			}
39 			msg += " -> Expected " + BitConverter.ToString (array1, 0);
40 			msg += " is different than " + BitConverter.ToString (array2, 0);
41 			Assert.IsTrue (a, msg);
42 		}
43 
44 		private const string xmldsig = " xmlns=\"http://www.w3.org/2000/09/xmldsig#\"";
45 
46 		// not to be used to test C14N output
AssertXmlEquals(string msg, string expected, string actual)47 		static public void AssertXmlEquals (string msg, string expected, string actual)
48 		{
49 			expected = expected.Replace (xmldsig, String.Empty);
50 			actual = actual.Replace (xmldsig, String.Empty);
51 			Assert.AreEqual (expected, actual, msg);
52 		}
53 	}
54 }
55