Pkcs9AttributeTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // Pkcs9AttributeTest.cs - NUnit tests for Pkcs9Attribute
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Security.Cryptography;
  33. using System.Security.Cryptography.Pkcs;
  34. namespace MonoTests.System.Security.Cryptography.Pkcs {
  35. [TestFixture]
  36. public class Pkcs9AttributeObjectTest {
  37. static string defaultOid = "1.2.840.113549.1.7.1";
  38. static string defaultName = "PKCS 7 Data";
  39. [Test]
  40. public void ConstructorEmpty ()
  41. {
  42. Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
  43. Assert.IsNull (a.Oid, "Oid");
  44. Assert.IsNull (a.RawData, "RawData");
  45. }
  46. [Test]
  47. [ExpectedException (typeof (ArgumentNullException))]
  48. public void ConstructorAsnEncodedDataNull ()
  49. {
  50. Pkcs9AttributeObject a = new Pkcs9AttributeObject (null);
  51. }
  52. [Test]
  53. public void ConstructorOidArray ()
  54. {
  55. Oid o = new Oid (defaultOid);
  56. Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
  57. Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
  58. Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
  59. Assert.AreEqual (0, a.RawData.Length, "RawData");
  60. }
  61. [Test]
  62. [ExpectedException (typeof (ArgumentNullException))]
  63. public void ConstructorOidNullArray ()
  64. {
  65. Oid o = null;
  66. Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
  67. }
  68. [Test]
  69. [ExpectedException (typeof (ArgumentNullException))]
  70. public void ConstructorOidArrayNull ()
  71. {
  72. Oid o = new Oid (defaultOid);
  73. Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, null);
  74. }
  75. [Test]
  76. public void ConstructorStringArray ()
  77. {
  78. Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, new byte[0]);
  79. Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
  80. Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
  81. Assert.AreEqual (0, a.RawData.Length, "RawData");
  82. }
  83. [Test]
  84. [ExpectedException (typeof (ArgumentNullException))]
  85. public void ConstructorStringNullArray ()
  86. {
  87. string s = null;
  88. Pkcs9AttributeObject a = new Pkcs9AttributeObject (s, new byte[0]);
  89. }
  90. [Test]
  91. [ExpectedException (typeof (ArgumentNullException))]
  92. public void ConstructorStringArrayNull ()
  93. {
  94. Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, null);
  95. }
  96. [Test]
  97. [ExpectedException (typeof (ArgumentNullException))]
  98. public void CopyFrom_Null ()
  99. {
  100. new Pkcs9AttributeObject ().CopyFrom (null);
  101. }
  102. [Test]
  103. [ExpectedException (typeof (ArgumentException))]
  104. public void CopyFrom_SigningTime_Raw ()
  105. {
  106. Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
  107. Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
  108. a.CopyFrom (new AsnEncodedData (st.RawData));
  109. }
  110. [Test]
  111. [ExpectedException (typeof (ArgumentException))]
  112. public void CopyFrom_SigningTime_OidRaw ()
  113. {
  114. Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
  115. Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
  116. a.CopyFrom (new AsnEncodedData (st.Oid, st.RawData));
  117. }
  118. [Test]
  119. [ExpectedException (typeof (ArgumentException))]
  120. public void CopyFrom_Self ()
  121. {
  122. Pkcs9AttributeObject a = new Pkcs9AttributeObject ("1.2.3.4", new byte[2] { 0x05, 0x00 } );
  123. a.CopyFrom (new AsnEncodedData (a.Oid, a.RawData));
  124. }
  125. }
  126. }