Pkcs7RecipientTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Pkcs7RecipientTest.cs - NUnit tests for Pkcs7Recipient
  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.Security.Cryptography;
  14. using System.Security.Cryptography.Pkcs;
  15. using System.Security.Cryptography.X509Certificates;
  16. using System.Security.Cryptography.Xml;
  17. namespace MonoTests.System.Security.Cryptography.Pkcs {
  18. [TestFixture]
  19. public class Pkcs7RecipientTest : Assertion {
  20. private X509CertificateEx GetCertificate (bool includePrivateKey)
  21. {
  22. return new X509CertificateEx (@"c:\farscape.p12.pfx", "farscape");
  23. }
  24. [Test]
  25. public void IssuerAndSerialNumber ()
  26. {
  27. X509CertificateEx x509 = GetCertificate (true);
  28. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.IssuerAndSerialNumber, x509);
  29. AssertEquals ("RecipientIdentifierType", SubjectIdentifierType.IssuerAndSerialNumber, p7r.RecipientIdentifierType);
  30. AssertEquals ("Certificate", x509.Thumbprint, p7r.Certificate.Thumbprint);
  31. }
  32. [Test]
  33. public void SubjectKeyIdentifier ()
  34. {
  35. X509CertificateEx x509 = GetCertificate (true);
  36. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.SubjectKeyIdentifier, x509);
  37. AssertEquals ("RecipientIdentifierType", SubjectIdentifierType.SubjectKeyIdentifier, p7r.RecipientIdentifierType);
  38. AssertEquals ("Certificate", x509.Thumbprint, p7r.Certificate.Thumbprint);
  39. }
  40. [Test]
  41. public void Unknown ()
  42. {
  43. X509CertificateEx x509 = GetCertificate (true);
  44. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.Unknown, x509);
  45. AssertEquals ("RecipientIdentifierType", SubjectIdentifierType.IssuerAndSerialNumber, p7r.RecipientIdentifierType);
  46. AssertEquals ("Certificate", x509.Thumbprint, p7r.Certificate.Thumbprint);
  47. }
  48. [Test]
  49. [ExpectedException (typeof (ArgumentNullException))]
  50. public void NullCertificate ()
  51. {
  52. Pkcs7Recipient p7r = new Pkcs7Recipient (SubjectIdentifierType.IssuerAndSerialNumber, null);
  53. }
  54. }
  55. }
  56. #endif