AssertCrypto.cs 1.4 KB

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