EnvelopedPkcs7Test.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. //
  2. // EnvelopedPkcs7Test.cs - NUnit tests for EnvelopedPkcs7
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. #if NET_2_0
  10. using NUnit.Framework;
  11. using System;
  12. using System.Collections;
  13. using System.IO;
  14. using System.Security.Cryptography;
  15. using System.Security.Cryptography.Pkcs;
  16. using System.Security.Cryptography.X509Certificates;
  17. namespace MonoTests.System.Security.Cryptography.Pkcs {
  18. [TestFixture]
  19. public class EnvelopedPkcs7Test : Assertion {
  20. static byte[] asnNull = { 0x05, 0x00 };
  21. static string tdesOid = "1.2.840.113549.3.7";
  22. static string tdesName = "3des";
  23. static string p7DataOid = "1.2.840.113549.1.7.1";
  24. static string p7DataName = "PKCS 7 Data";
  25. private void DefaultProperties (EnvelopedPkcs7 ep, int contentLength, int version)
  26. {
  27. AssertEquals ("Certificates", 0, ep.Certificates.Count);
  28. AssertEquals ("ContentEncryptionAlgorithm.KeyLength", 0, ep.ContentEncryptionAlgorithm.KeyLength);
  29. AssertEquals ("ContentEncryptionAlgorithm.Oid.FriendlyName", tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName);
  30. AssertEquals ("ContentEncryptionAlgorithm.Oid.Value", tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value);
  31. AssertEquals ("ContentEncryptionAlgorithm.Parameters", 0, ep.ContentEncryptionAlgorithm.Parameters.Length);
  32. AssertEquals ("ContentInfo.ContentType.FriendlyName", p7DataName, ep.ContentInfo.ContentType.FriendlyName);
  33. AssertEquals ("ContentInfo.ContentType.Value", p7DataOid, ep.ContentInfo.ContentType.Value);
  34. AssertEquals ("ContentInfo.Content", contentLength, ep.ContentInfo.Content.Length);
  35. AssertEquals ("RecipientInfos", 0, ep.RecipientInfos.Count);
  36. AssertEquals ("UnprotectedAttributes", 0, ep.UnprotectedAttributes.Count);
  37. AssertEquals ("Version", version, ep.Version);
  38. }
  39. private X509CertificateEx GetCertificate (bool includePrivateKey)
  40. {
  41. return new X509CertificateEx (@"c:\farscape.p12.pfx", "farscape");
  42. }
  43. [Test]
  44. public void ConstructorEmpty ()
  45. {
  46. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  47. DefaultProperties (ep, 0, 0);
  48. }
  49. [Test]
  50. public void ConstructorContentInfo ()
  51. {
  52. ContentInfo ci = new ContentInfo (asnNull);
  53. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (ci);
  54. DefaultProperties (ep, asnNull.Length, 0);
  55. }
  56. [Test]
  57. [ExpectedException (typeof (ArgumentNullException))]
  58. public void ConstructorContentInfoNull ()
  59. {
  60. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (null);
  61. }
  62. [Test]
  63. public void ConstructorContentInfoAlgorithmIdentifier ()
  64. {
  65. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  66. ContentInfo ci = new ContentInfo (asnNull);
  67. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (ci, ai);
  68. DefaultProperties (ep, 2, 0);
  69. }
  70. [Test]
  71. [ExpectedException (typeof (ArgumentNullException))]
  72. public void ConstructorContentInfoNullAlgorithmIdentifier ()
  73. {
  74. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  75. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (null, ai);
  76. }
  77. [Test]
  78. [ExpectedException (typeof (ArgumentNullException))]
  79. public void ConstructorContentInfoAlgorithmIdentifierNull ()
  80. {
  81. ContentInfo ci = new ContentInfo (asnNull);
  82. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (ci, null);
  83. }
  84. [Test]
  85. public void ConstructorSubjectIdentifierTypeIssuerAndSerialNumberContentInfoAlgorithmIdentifier ()
  86. {
  87. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  88. ContentInfo ci = new ContentInfo (asnNull);
  89. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.IssuerAndSerialNumber, ci, ai);
  90. DefaultProperties (ep, 2, 0);
  91. }
  92. [Test]
  93. public void ConstructorSubjectIdentifierTypeSubjectKeyIdentifierContentInfoAlgorithmIdentifier ()
  94. {
  95. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  96. ContentInfo ci = new ContentInfo (asnNull);
  97. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.SubjectKeyIdentifier, ci, ai);
  98. DefaultProperties (ep, 2, 2);
  99. }
  100. [Test]
  101. public void ConstructorSubjectIdentifierTypeUnknownContentInfoAlgorithmIdentifier ()
  102. {
  103. AlgorithmIdentifier ai = new AlgorithmIdentifier ();
  104. ContentInfo ci = new ContentInfo (asnNull);
  105. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.Unknown, ci, ai);
  106. DefaultProperties (ep, 2, 0);
  107. }
  108. [Test]
  109. public void ConstructorSubjectIdentifierTypeIssuerAndSerialNumberContentInfo ()
  110. {
  111. ContentInfo ci = new ContentInfo (asnNull);
  112. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  113. DefaultProperties (ep, 2, 0);
  114. }
  115. [Test]
  116. public void ConstructorSubjectIdentifierTypeSubjectKeyIdentifierContentInfo ()
  117. {
  118. ContentInfo ci = new ContentInfo (asnNull);
  119. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.SubjectKeyIdentifier, ci);
  120. DefaultProperties (ep, 2, 2);
  121. }
  122. [Test]
  123. public void ConstructorSubjectIdentifierTypeUnknownContentInfo ()
  124. {
  125. ContentInfo ci = new ContentInfo (asnNull);
  126. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.Unknown, ci);
  127. DefaultProperties (ep, 2, 0);
  128. }
  129. [Test]
  130. public void Decode ()
  131. {
  132. byte[] encoded = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0xCA, 0x4B, 0x97, 0x9C, 0xAB, 0x79, 0xC6, 0xDF, 0x6A, 0x27, 0xC7, 0x24, 0xC4, 0x5E, 0x3B, 0x31, 0xAD, 0xBC, 0x25, 0xE6, 0x38, 0x5E, 0x79, 0x26, 0x0E, 0x68, 0x46, 0x1D, 0x21, 0x81, 0x38, 0x92, 0xEC, 0xCB, 0x7C, 0x91, 0xD6, 0x09, 0x38, 0x91, 0xCE, 0x50, 0x5B, 0x70, 0x31, 0xB0, 0x9F, 0xFC, 0xE2, 0xEE, 0x45, 0xBC, 0x4B, 0xF8, 0x9A, 0xD9, 0xEE, 0xE7, 0x4A, 0x3D, 0xCD, 0x8D, 0xFF, 0x10, 0xAB, 0xC8, 0x19, 0x05, 0x54, 0x5E, 0x40, 0x7A, 0xBE, 0x2B, 0xD7, 0x22, 0x97, 0xF3, 0x23, 0xAF, 0x50, 0xF5, 0xEB, 0x43, 0x06, 0xC3, 0xFB, 0x17, 0xCA, 0xBD, 0xAD, 0x28, 0xD8, 0x10, 0x0F, 0x61, 0xCE, 0xF8, 0x25, 0x70, 0xF6, 0xC8, 0x1E, 0x7F, 0x82, 0xE5, 0x94, 0xEB, 0x11, 0xBF, 0xB8, 0x6F, 0xEE, 0x79, 0xCD, 0x63, 0xDD, 0x59, 0x8D, 0x25, 0x0E, 0x78, 0x55, 0xCE, 0x21, 0xBA, 0x13, 0x6B, 0x30, 0x2B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
  133. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  134. ep.Decode (encoded);
  135. // properties
  136. AssertEquals ("Certificates", 0, ep.Certificates.Count);
  137. AssertEquals ("ContentEncryptionAlgorithm.KeyLength", 192, ep.ContentEncryptionAlgorithm.KeyLength);
  138. AssertEquals ("ContentEncryptionAlgorithm.Oid.FriendlyName", tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName);
  139. AssertEquals ("ContentEncryptionAlgorithm.Oid.Value", tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value);
  140. AssertEquals ("ContentEncryptionAlgorithm.Parameters", 16, ep.ContentEncryptionAlgorithm.Parameters.Length);
  141. AssertEquals ("ContentInfo.ContentType.FriendlyName", p7DataName, ep.ContentInfo.ContentType.FriendlyName);
  142. AssertEquals ("ContentInfo.ContentType.Value", p7DataOid, ep.ContentInfo.ContentType.Value);
  143. AssertEquals ("ContentInfo.Content", 14, ep.ContentInfo.Content.Length);
  144. AssertEquals ("RecipientInfos", 1, ep.RecipientInfos.Count);
  145. RecipientInfo ri = ep.RecipientInfos [0];
  146. Assert ("RecipientInfos is KeyTransRecipientInfo", (ri is KeyTransRecipientInfo));
  147. AssertEquals ("UnprotectedAttributes", 0, ep.UnprotectedAttributes.Count);
  148. AssertEquals ("Version", 0, ep.Version);
  149. }
  150. [Test]
  151. [ExpectedException (typeof (ArgumentNullException))]
  152. public void DecodeNull ()
  153. {
  154. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  155. ep.Decode (null);
  156. }
  157. [Test]
  158. [ExpectedException (typeof (InvalidOperationException))]
  159. public void EncodeEmpty ()
  160. {
  161. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  162. byte[] encoded = ep.Encode ();
  163. }
  164. [Test]
  165. public void Decrypt ()
  166. {
  167. byte[] encoded = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0xCA, 0x4B, 0x97, 0x9C, 0xAB, 0x79, 0xC6, 0xDF, 0x6A, 0x27, 0xC7, 0x24, 0xC4, 0x5E, 0x3B, 0x31, 0xAD, 0xBC, 0x25, 0xE6, 0x38, 0x5E, 0x79, 0x26, 0x0E, 0x68, 0x46, 0x1D, 0x21, 0x81, 0x38, 0x92, 0xEC, 0xCB, 0x7C, 0x91, 0xD6, 0x09, 0x38, 0x91, 0xCE, 0x50, 0x5B, 0x70, 0x31, 0xB0, 0x9F, 0xFC, 0xE2, 0xEE, 0x45, 0xBC, 0x4B, 0xF8, 0x9A, 0xD9, 0xEE, 0xE7, 0x4A, 0x3D, 0xCD, 0x8D, 0xFF, 0x10, 0xAB, 0xC8, 0x19, 0x05, 0x54, 0x5E, 0x40, 0x7A, 0xBE, 0x2B, 0xD7, 0x22, 0x97, 0xF3, 0x23, 0xAF, 0x50, 0xF5, 0xEB, 0x43, 0x06, 0xC3, 0xFB, 0x17, 0xCA, 0xBD, 0xAD, 0x28, 0xD8, 0x10, 0x0F, 0x61, 0xCE, 0xF8, 0x25, 0x70, 0xF6, 0xC8, 0x1E, 0x7F, 0x82, 0xE5, 0x94, 0xEB, 0x11, 0xBF, 0xB8, 0x6F, 0xEE, 0x79, 0xCD, 0x63, 0xDD, 0x59, 0x8D, 0x25, 0x0E, 0x78, 0x55, 0xCE, 0x21, 0xBA, 0x13, 0x6B, 0x30, 0x2B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
  168. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  169. ep.Decode (encoded);
  170. X509CertificateEx x509 = GetCertificate (true);
  171. X509CertificateExCollection xc = new X509CertificateExCollection ();
  172. xc.Add (x509);
  173. ep.Decrypt (xc);
  174. // properties
  175. AssertEquals ("Certificates", 0, ep.Certificates.Count);
  176. AssertEquals ("ContentEncryptionAlgorithm.KeyLength", 192, ep.ContentEncryptionAlgorithm.KeyLength);
  177. AssertEquals ("ContentEncryptionAlgorithm.Oid.FriendlyName", tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName);
  178. AssertEquals ("ContentEncryptionAlgorithm.Oid.Value", tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value);
  179. AssertEquals ("ContentEncryptionAlgorithm.Parameters", 16, ep.ContentEncryptionAlgorithm.Parameters.Length);
  180. AssertEquals ("ContentInfo.ContentType.FriendlyName", p7DataName, ep.ContentInfo.ContentType.FriendlyName);
  181. AssertEquals ("ContentInfo.ContentType.Value", p7DataOid, ep.ContentInfo.ContentType.Value);
  182. AssertEquals ("ContentInfo.Content", "05-00", BitConverter.ToString (ep.ContentInfo.Content));
  183. AssertEquals ("RecipientInfos", 1, ep.RecipientInfos.Count);
  184. AssertEquals ("UnprotectedAttributes", 0, ep.UnprotectedAttributes.Count);
  185. AssertEquals ("Version", 0, ep.Version);
  186. }
  187. [Test]
  188. [ExpectedException (typeof (InvalidOperationException))]
  189. public void DecryptEmpty ()
  190. {
  191. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  192. ep.Decrypt ();
  193. }
  194. [Test]
  195. [ExpectedException (typeof (ArgumentNullException))]
  196. public void DecryptRecipientInfoNull ()
  197. {
  198. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  199. RecipientInfo ri = null; // do not confuse compiler
  200. ep.Decrypt (ri);
  201. }
  202. [Test]
  203. [ExpectedException (typeof (ArgumentNullException))]
  204. public void DecryptX509CertificateExCollectionNull ()
  205. {
  206. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  207. X509CertificateExCollection xec = null; // do not confuse compiler
  208. ep.Decrypt (xec);
  209. }
  210. [Test]
  211. [ExpectedException (typeof (ArgumentNullException))]
  212. public void DecryptRecipientInfoX509CertificateExCollectionNull ()
  213. {
  214. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  215. X509CertificateExCollection xec = new X509CertificateExCollection ();
  216. ep.Decrypt (null, xec);
  217. }
  218. /* [Test]
  219. [ExpectedException (typeof (ArgumentNullException))]
  220. public void DecryptX509CertificateExCollectionNull ()
  221. {
  222. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  223. RecipientInfo ri =
  224. ep.Decrypt (ri, null);
  225. }*/
  226. private void RoundTrip (byte[] encoded)
  227. {
  228. X509CertificateExCollection xc = new X509CertificateExCollection ();
  229. xc.Add (GetCertificate (true));
  230. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  231. ep.Decode (encoded);
  232. ep.Decrypt (xc);
  233. AssertEquals ("ContentInfo.Content", "05-00", BitConverter.ToString (ep.ContentInfo.Content));
  234. }
  235. [Test]
  236. public void EncryptPkcs7RecipientIssuerAndSerialNumber ()
  237. {
  238. ContentInfo ci = new ContentInfo (asnNull);
  239. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  240. X509CertificateEx x509 = GetCertificate (false);
  241. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.IssuerAndSerialNumber, x509);
  242. ep.Encrypt (p7r);
  243. byte[] encoded = ep.Encode ();
  244. FileStream fs = File.OpenWrite ("EncryptPkcs7RecipientIssuerAndSerialNumber.der");
  245. fs.Write (encoded, 0, encoded.Length);
  246. fs.Close ();
  247. RoundTrip (encoded);
  248. }
  249. [Test]
  250. public void EncryptPkcs7RecipientSubjectKeyIdentifier ()
  251. {
  252. ContentInfo ci = new ContentInfo (asnNull);
  253. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  254. X509CertificateEx x509 = GetCertificate (false);
  255. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.SubjectKeyIdentifier, x509);
  256. ep.Encrypt (p7r);
  257. byte[] encoded = ep.Encode ();
  258. FileStream fs = File.OpenWrite ("EncryptPkcs7RecipientSubjectKeyIdentifier.der");
  259. fs.Write (encoded, 0, encoded.Length);
  260. fs.Close ();
  261. RoundTrip (encoded);
  262. }
  263. [Test]
  264. public void EncryptPkcs7RecipientUnknown ()
  265. {
  266. ContentInfo ci = new ContentInfo (asnNull);
  267. EnvelopedPkcs7 ep = new EnvelopedPkcs7 (SubjectIdentifierType.IssuerAndSerialNumber, ci);
  268. X509CertificateEx x509 = GetCertificate (false);
  269. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.Unknown, x509);
  270. ep.Encrypt (p7r);
  271. byte[] encoded = ep.Encode ();
  272. FileStream fs = File.OpenWrite ("EncryptPkcs7RecipientUnknown.der");
  273. fs.Write (encoded, 0, encoded.Length);
  274. fs.Close ();
  275. RoundTrip (encoded);
  276. }
  277. [Test]
  278. [ExpectedException (typeof (CryptographicException))]
  279. public void EncryptEmpty ()
  280. {
  281. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  282. ep.Encrypt ();
  283. }
  284. [Test]
  285. [ExpectedException (typeof (ArgumentNullException))]
  286. public void EncryptPkcs7RecipientNull ()
  287. {
  288. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  289. Pkcs7Recipient p7r = null; // do not confuse compiler
  290. ep.Encrypt (p7r);
  291. }
  292. [Test]
  293. [ExpectedException (typeof (ArgumentNullException))]
  294. public void EncryptPkcs7RecipientCollectionNull ()
  295. {
  296. EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
  297. Pkcs7RecipientCollection p7rc = null; // do not confuse compiler
  298. ep.Encrypt (p7rc);
  299. }
  300. }
  301. }
  302. #endif