AsnEncodedDataTest.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // AsnEncodedDataTest.cs - NUnit tests for AsnEncodedData
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. #if NET_1_2
  10. using NUnit.Framework;
  11. using System;
  12. using System.Security.Cryptography;
  13. namespace MonoTests.System.Security.Cryptography {
  14. [TestFixture]
  15. public class AsnEncodedDataTest : Assertion {
  16. static byte[] asnNullBytes = { 0x05, 0x00 };
  17. static string asnNullString = "05 00";
  18. static byte[] asnLongBytes = { 0x30,0x5C,0x02,0x55,0x2D,0x58,0xE9,0xBF,0xF0,0x31,0xCD,0x79,0x06,0x50,0x5A,0xD5,0x9E,0x0E,0x2C,0xE6,0xC2,0xF7,0xF9,0xD2,0xCE,0x55,0x64,0x85,0xB1,0x90,0x9A,0x92,0xB3,0x36,0xC1,0xBC,0xEA,0xC8,0x23,0xB7,0xAB,0x3A,0xA7,0x64,0x63,0x77,0x5F,0x84,0x22,0x8E,0xE5,0xB6,0x45,0xDD,0x46,0xAE,0x0A,0xDD,0x00,0xC2,0x1F,0xBA,0xD9,0xAD,0xC0,0x75,0x62,0xF8,0x95,0x82,0xA2,0x80,0xB1,0x82,0x69,0xFA,0xE1,0xAF,0x7F,0xBC,0x7D,0xE2,0x7C,0x76,0xD5,0xBC,0x2A,0x80,0xFB,0x02,0x03,0x01,0x00,0x01 };
  19. static string asnLongString = "30 5c 02 55 2d 58 e9 bf f0 31 cd 79 06 50 5a d5 9e 0e 2c e6 c2 f7 f9 d2 ce 55 64 85 b1 90 9a 92 b3 36 c1 bc ea c8 23 b7 ab 3a a7 64 63 77 5f 84 22 8e e5 b6 45 dd 46 ae 0a dd 00 c2 1f ba d9 ad c0 75 62 f8 95 82 a2 80 b1 82 69 fa e1 af 7f bc 7d e2 7c 76 d5 bc 2a 80 fb 02 03 01 00 01";
  20. private void AssertEquals (string message, byte[] expected, byte[] actual)
  21. {
  22. AssertEquals (message, BitConverter.ToString (expected), BitConverter.ToString (actual));
  23. }
  24. [Test]
  25. public void ConstructorStringData ()
  26. {
  27. AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
  28. AssertEquals ("Format", asnNullString, aed.Format (true));
  29. }
  30. [Test]
  31. [ExpectedException (typeof (ArgumentNullException))]
  32. public void ConstructorStringNullData ()
  33. {
  34. string oid = null; // do not confuse compiler
  35. AsnEncodedData aed = new AsnEncodedData (oid, asnNullBytes);
  36. AssertEquals ("Format", asnNullString, aed.Format (true));
  37. }
  38. [Test]
  39. //BUG [ExpectedException (typeof (ArgumentNullException))]
  40. [ExpectedException (typeof (NullReferenceException))]
  41. public void ConstructorStringDataNull ()
  42. {
  43. AsnEncodedData aed = new AsnEncodedData ("oid", null);
  44. AssertEquals ("Format", asnNullString, aed.Format (true));
  45. }
  46. [Test]
  47. public void ConstructorOidData ()
  48. {
  49. Oid o = new Oid ("1.0");
  50. AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
  51. AssertEquals ("Format", asnNullString, aed.Format (true));
  52. }
  53. [Test]
  54. //BUG [ExpectedException (typeof (ArgumentNullException))]
  55. [ExpectedException (typeof (NullReferenceException))]
  56. public void ConstructorOidNullData ()
  57. {
  58. Oid o = null;
  59. AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
  60. }
  61. [Test]
  62. //BUG [ExpectedException (typeof (ArgumentNullException))]
  63. [ExpectedException (typeof (NullReferenceException))]
  64. public void ConstructorOidDataNull ()
  65. {
  66. Oid o = new Oid ("1.0");
  67. AsnEncodedData aed = new AsnEncodedData (o, null);
  68. }
  69. [Test]
  70. public void ConstructorAsn ()
  71. {
  72. AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
  73. AsnEncodedData aed2 = new AsnEncodedData (aed);
  74. AssertEquals ("FriendlyName", aed.RawData, aed2.RawData);
  75. string s1 = aed.Format (false);
  76. string s2 = aed.Format (true);
  77. AssertEquals ("Format", s1, s2);
  78. }
  79. [Test]
  80. //BUG [ExpectedException (typeof (ArgumentNullException))]
  81. [ExpectedException (typeof (NullReferenceException))]
  82. public void ConstructorAsnNull ()
  83. {
  84. AsnEncodedData aed = new AsnEncodedData (null);
  85. }
  86. [Test]
  87. public void Format ()
  88. {
  89. AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
  90. string result = aed.Format (false);
  91. AssertEquals ("Format(false)", asnLongString, result);
  92. }
  93. [Test]
  94. public void FormatMultiline ()
  95. {
  96. AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
  97. string result = aed.Format (true);
  98. AssertEquals ("Format(true)", asnLongString, result);
  99. }
  100. }
  101. }
  102. #endif