DSAKeyValueTest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #if !MOBILE
  10. using System;
  11. using System.Security.Cryptography;
  12. using System.Security.Cryptography.Xml;
  13. using System.Xml;
  14. using NUnit.Framework;
  15. namespace MonoTests.System.Security.Cryptography.Xml {
  16. [TestFixture]
  17. public class DSAKeyValueTest {
  18. [Test]
  19. public void GenerateKey ()
  20. {
  21. DSAKeyValue dsa1 = new DSAKeyValue ();
  22. Assert.IsNotNull (dsa1.Key, "Key");
  23. XmlElement xmlkey = dsa1.GetXml ();
  24. DSAKeyValue dsa2 = new DSAKeyValue ();
  25. dsa2.LoadXml (xmlkey);
  26. Assert.IsTrue ((dsa1.GetXml ().OuterXml) == (dsa2.GetXml ().OuterXml), "dsa1==dsa2");
  27. DSA key = dsa1.Key;
  28. DSAKeyValue dsa3 = new DSAKeyValue (key);
  29. Assert.IsTrue ((dsa3.GetXml ().OuterXml) == (dsa1.GetXml ().OuterXml), "dsa3==dsa1");
  30. Assert.IsTrue ((dsa3.GetXml ().OuterXml) == (dsa2.GetXml ().OuterXml), "dsa3==dsa2");
  31. }
  32. [Test]
  33. public void ImportKey ()
  34. {
  35. 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>";
  36. XmlDocument doc = new XmlDocument ();
  37. doc.LoadXml (dsaKey);
  38. DSAKeyValue dsa1 = new DSAKeyValue ();
  39. dsa1.LoadXml (doc.DocumentElement);
  40. string s = (dsa1.GetXml ().OuterXml);
  41. Assert.AreEqual (dsaKey, s, "DSA Key");
  42. }
  43. [Test]
  44. [ExpectedException (typeof (ArgumentNullException))]
  45. public void InvalidValue1 ()
  46. {
  47. string badKey = "<Test></Test>";
  48. XmlDocument doc = new XmlDocument ();
  49. doc.LoadXml (badKey);
  50. DSAKeyValue dsa1 = new DSAKeyValue ();
  51. dsa1.LoadXml (null);
  52. }
  53. [Test]
  54. [ExpectedException (typeof (CryptographicException))]
  55. public void InvalidValue2 ()
  56. {
  57. string badKey = "<Test></Test>";
  58. XmlDocument doc = new XmlDocument ();
  59. doc.LoadXml (badKey);
  60. DSAKeyValue dsa1 = new DSAKeyValue ();
  61. dsa1.LoadXml (doc.DocumentElement);
  62. }
  63. }
  64. }
  65. #endif