DSAKeyValueTest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // DSAKeyValueTest.cs - NUnit Test Cases for DSAKeyValue
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System;
  10. using System.Security.Cryptography;
  11. using System.Security.Cryptography.Xml;
  12. using System.Xml;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Security.Cryptography.Xml {
  15. [TestFixture]
  16. public class DSAKeyValueTest {
  17. [Test]
  18. public void GenerateKey ()
  19. {
  20. DSAKeyValue dsa1 = new DSAKeyValue ();
  21. Assert.IsNotNull (dsa1.Key, "Key");
  22. XmlElement xmlkey = dsa1.GetXml ();
  23. DSAKeyValue dsa2 = new DSAKeyValue ();
  24. dsa2.LoadXml (xmlkey);
  25. Assert.IsTrue ((dsa1.GetXml ().OuterXml) == (dsa2.GetXml ().OuterXml), "dsa1==dsa2");
  26. DSA key = dsa1.Key;
  27. DSAKeyValue dsa3 = new DSAKeyValue (key);
  28. Assert.IsTrue ((dsa3.GetXml ().OuterXml) == (dsa1.GetXml ().OuterXml), "dsa3==dsa1");
  29. Assert.IsTrue ((dsa3.GetXml ().OuterXml) == (dsa2.GetXml ().OuterXml), "dsa3==dsa2");
  30. }
  31. [Test]
  32. public void ImportKey ()
  33. {
  34. string dsaKey = "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>xc+QZRWTgr390gzwNXF+WzoepZkvAQvCzfCm+YyXj0KPoeHHeSc5ORzXQw81V+7XJR3gupvlI4F7lW9YC538l+3eqGm8IQlCIS+U+7ICTDOFFKevqsYX0BnjO0vvE4aAtDyxfSOTCOAo1cJ+6G6xgcC1JGIBEYCtg1tH8wUewDE=</P><Q>yyfZb0S/rimXl9ScJ3zIba2oGl8=</Q><G>crLazMg+vgI7u6+Idgi9iTLdRa4fptat3gdY97zcc857+OVdmT+lVRpK3okWpmBbw2wSffU8QltwFf42BVs+/HGUOUo2hNqSSXgzl1i+1frO7/cqooHVcy5WX0xxaIPsKcREPI5pNPj/3g8apTgErLMGsHkFdngwbMed9DArTks=</G><Y>FlAozo17wV/LCMRrtnmMKxVQNpidJVkZNM1/0eR65x8giwPs6yXzJmFT8f2tmPJY2FIOAtp5JYin4xUhwIHF452Gg50wUrjV6WTGkiC+gzLC2fVIyGlVsFecLj6ue7J+MACG+b3NQnxFuT5maQnPnEeuGgjLXfwYsAR1vfU0Gas=</Y><J>+UPMvUPq9Fo6Q1fr2oEYDxfGMMtfdoQmVBxI+TkUYQsReodRzBbnvGV1uPLWTpKKd/uJNUHO/QGb05Cvc6u49/AToDJIyi4e01hTLNCzeQk/Hj19gowb5wkTIjyaH04VyPE5zYoTYfuu3Y3Q</J><Seed>+cvoO7bzdpAwAjnDDApPzBCl6zg=</Seed><PgenCounter>ATM=</PgenCounter></DSAKeyValue></KeyValue>";
  35. XmlDocument doc = new XmlDocument ();
  36. doc.LoadXml (dsaKey);
  37. DSAKeyValue dsa1 = new DSAKeyValue ();
  38. dsa1.LoadXml (doc.DocumentElement);
  39. string s = (dsa1.GetXml ().OuterXml);
  40. Assert.AreEqual (dsaKey, s, "DSA Key");
  41. }
  42. [Test]
  43. [ExpectedException (typeof (ArgumentNullException))]
  44. public void InvalidValue1 ()
  45. {
  46. string badKey = "<Test></Test>";
  47. XmlDocument doc = new XmlDocument ();
  48. doc.LoadXml (badKey);
  49. DSAKeyValue dsa1 = new DSAKeyValue ();
  50. dsa1.LoadXml (null);
  51. }
  52. [Test]
  53. [ExpectedException (typeof (CryptographicException))]
  54. public void InvalidValue2 ()
  55. {
  56. string badKey = "<Test></Test>";
  57. XmlDocument doc = new XmlDocument ();
  58. doc.LoadXml (badKey);
  59. DSAKeyValue dsa1 = new DSAKeyValue ();
  60. dsa1.LoadXml (doc.DocumentElement);
  61. }
  62. }
  63. }