Esempio n. 1
0
        public void TestMultipartEncryptedEncryptAlgorithmUsingKeys()
        {
            var body = new TextPart("plain")
            {
                Text = "This is some cleartext that we'll end up encrypting..."
            };
            var self = new MailboxAddress("MimeKit UnitTests", "*****@*****.**");
            IList <PgpPublicKey> recipients;

            using (var ctx = new DummyOpenPgpContext()) {
                recipients = ctx.GetPublicKeys(new [] { self });
            }

            foreach (EncryptionAlgorithm algorithm in Enum.GetValues(typeof(EncryptionAlgorithm)))
            {
                if (algorithm == EncryptionAlgorithm.RC240 ||
                    algorithm == EncryptionAlgorithm.RC264 ||
                    algorithm == EncryptionAlgorithm.RC2128)
                {
                    continue;
                }

                var encrypted = MultipartEncrypted.Encrypt(algorithm, recipients, body);

                //using (var file = File.Create ("pgp-encrypted.asc"))
                //	encrypted.WriteTo (file);

                var decrypted = encrypted.Decrypt();

                Assert.IsInstanceOf <TextPart> (decrypted, "Decrypted part is not the expected type.");
                Assert.AreEqual(body.Text, ((TextPart)decrypted).Text, "Decrypted content is not the same as the original.");
            }
        }
Esempio n. 2
0
        public void TestMultipartEncryptedSignAndEncryptALgorithmUsingKeys()
        {
            var body = new TextPart("plain")
            {
                Text = "This is some cleartext that we'll end up signing and encrypting..."
            };
            var self = new SecureMailboxAddress("MimeKit UnitTests", "*****@*****.**", "AB0821A2");
            DigitalSignatureCollection signatures;
            IList <PgpPublicKey>       recipients;
            PgpSecretKey signer;

            using (var ctx = new DummyOpenPgpContext()) {
                recipients = ctx.GetPublicKeys(new [] { self });
                signer     = ctx.GetSigningKey(self);
            }

            var encrypted = MultipartEncrypted.SignAndEncrypt(signer, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, recipients, body);

            //using (var file = File.Create ("pgp-signed-encrypted.asc"))
            //	encrypted.WriteTo (file);

            var decrypted = encrypted.Decrypt(out signatures);

            Assert.IsInstanceOf <TextPart> (decrypted, "Decrypted part is not the expected type.");
            Assert.AreEqual(body.Text, ((TextPart)decrypted).Text, "Decrypted content is not the same as the original.");

            Assert.AreEqual(1, signatures.Count, "Verify returned an unexpected number of signatures.");
            foreach (var signature in signatures)
            {
                try {
                    bool valid = signature.Verify();

                    Assert.IsTrue(valid, "Bad signature from {0}", signature.SignerCertificate.Email);
                } catch (DigitalSignatureVerifyException ex) {
                    Assert.Fail("Failed to verify signature: {0}", ex);
                }
            }
        }
Esempio n. 3
0
        public void TestArgumentExceptions()
        {
            Assert.Throws <ArgumentNullException> (() => CryptographyContext.Create(null));
            Assert.Throws <ArgumentNullException> (() => CryptographyContext.Register((Type)null));
            Assert.Throws <ArgumentNullException> (() => CryptographyContext.Register((Func <OpenPgpContext>)null));
            Assert.Throws <ArgumentNullException> (() => CryptographyContext.Register((Func <SecureMimeContext>)null));

            using (var ctx = new DummyOpenPgpContext()) {
                var mailboxes      = new [] { new MailboxAddress("MimeKit UnitTests", "*****@*****.**") };
                var emptyMailboxes = new MailboxAddress[0];
                var pubkeys        = ctx.GetPublicKeys(mailboxes);
                var key            = ctx.GetSigningKey(mailboxes[0]);
                var emptyPubkeys   = new PgpPublicKey[0];
                var stream         = new MemoryStream();

                Assert.Throws <ArgumentException> (() => ctx.KeyServer = new Uri("relative/uri", UriKind.Relative));

                Assert.Throws <ArgumentNullException> (() => ctx.GetDigestAlgorithm(null));
                Assert.Throws <ArgumentOutOfRangeException> (() => ctx.GetDigestAlgorithmName(DigestAlgorithm.DoubleSha));
                Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.DoubleSha));
                Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.Tiger192));
                Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.Haval5160));
                Assert.Throws <NotSupportedException> (() => OpenPgpContext.GetHashAlgorithm(DigestAlgorithm.MD4));
                Assert.Throws <ArgumentOutOfRangeException> (() => OpenPgpContext.GetDigestAlgorithm((Org.BouncyCastle.Bcpg.HashAlgorithmTag) 1024));

                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpEncrypted((MimeEntityConstructorArgs)null));
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature((MimeEntityConstructorArgs)null));
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature((Stream)null));

                // Accept
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpEncrypted().Accept(null));
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature(stream).Accept(null));

                // Decrypt
                Assert.Throws <ArgumentNullException> (() => ctx.Decrypt(null), "Decrypt");

                // Encrypt
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, (MailboxAddress[])null, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt((MailboxAddress[])null, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt((PgpPublicKey[])null, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(emptyMailboxes, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(emptyPubkeys, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, mailboxes, null), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, pubkeys, null), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(mailboxes, null), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(pubkeys, null), "Encrypt");

                // Export
                Assert.Throws <ArgumentNullException> (() => ctx.Export((PgpPublicKeyRingBundle)null), "Export");
                Assert.Throws <ArgumentNullException> (() => ctx.Export((MailboxAddress[])null), "Export");
                Assert.Throws <ArgumentNullException> (() => ctx.Export((PgpPublicKey[])null), "Export");

                // GetDecryptedStream
                Assert.Throws <ArgumentNullException> (() => ctx.GetDecryptedStream(null), "GetDecryptedStream");

                // GetDigestAlgorithmName
                Assert.Throws <ArgumentOutOfRangeException> (() => ctx.GetDigestAlgorithmName(DigestAlgorithm.None), "GetDigestAlgorithmName");

                // Import
                Assert.Throws <ArgumentNullException> (() => ctx.Import((Stream)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpPublicKeyRing)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpPublicKeyRingBundle)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpSecretKeyRing)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpSecretKeyRingBundle)null), "Import");

                // ImportSecretKeys
                Assert.Throws <ArgumentNullException> (() => ctx.ImportSecretKeys(null), "ImportSecretKeys");

                // Sign
                Assert.Throws <ArgumentNullException> (() => ctx.Sign((MailboxAddress)null, DigestAlgorithm.Sha1, stream), "Sign");
                Assert.Throws <ArgumentNullException> (() => ctx.Sign((PgpSecretKey)null, DigestAlgorithm.Sha1, stream), "Sign");
                Assert.Throws <ArgumentNullException> (() => ctx.Sign(mailboxes[0], DigestAlgorithm.Sha1, null), "Sign");
                Assert.Throws <ArgumentNullException> (() => ctx.Sign(key, DigestAlgorithm.Sha1, null), "Sign");

                // SignAndEncrypt
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (MailboxAddress[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, null), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, null), "SignAndEncrypt");

                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, mailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, pubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, (MailboxAddress[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, (PgpPublicKey[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, emptyMailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, emptyPubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, mailboxes, null), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, pubkeys, null), "SignAndEncrypt");

                // Supports
                Assert.Throws <ArgumentNullException> (() => ctx.Supports(null), "Supports");

                // Verify
                Assert.Throws <ArgumentNullException> (() => ctx.Verify(null, stream), "Verify");
                Assert.Throws <ArgumentNullException> (() => ctx.Verify(stream, null), "Verify");
            }
        }
Esempio n. 4
0
		public void TestArgumentExceptions ()
		{
			using (var ctx = new DummyOpenPgpContext ()) {
				var mailboxes = new [] { new MailboxAddress ("MimeKit UnitTests", "*****@*****.**") };
				var emptyMailboxes = new MailboxAddress[0];
				var pubkeys = ctx.GetPublicKeys (mailboxes);
				var key = ctx.GetSigningKey (mailboxes[0]);
				var emptyPubkeys = new PgpPublicKey[0];
				var stream = new MemoryStream ();

				Assert.Throws<ArgumentNullException> (() => new ApplicationPgpEncrypted ((MimeEntityConstructorArgs) null));
				Assert.Throws<ArgumentNullException> (() => new ApplicationPgpSignature ((MimeEntityConstructorArgs) null));
				Assert.Throws<ArgumentNullException> (() => new ApplicationPgpSignature ((Stream) null));

				// Accept
				Assert.Throws<ArgumentNullException> (() => new ApplicationPgpEncrypted ().Accept (null));
				Assert.Throws<ArgumentNullException> (() => new ApplicationPgpSignature (stream).Accept (null));

				// Decrypt
				Assert.Throws<ArgumentNullException> (() => ctx.Decrypt (null), "Decrypt");

				// Encrypt
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt (EncryptionAlgorithm.Cast5, (MailboxAddress[]) null, stream), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt (EncryptionAlgorithm.Cast5, (PgpPublicKey[]) null, stream), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt ((MailboxAddress[]) null, stream), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt ((PgpPublicKey[]) null, stream), "Encrypt");
				Assert.Throws<ArgumentException> (() => ctx.Encrypt (EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "Encrypt");
				Assert.Throws<ArgumentException> (() => ctx.Encrypt (EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "Encrypt");
				Assert.Throws<ArgumentException> (() => ctx.Encrypt (emptyMailboxes, stream), "Encrypt");
				Assert.Throws<ArgumentException> (() => ctx.Encrypt (emptyPubkeys, stream), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt (EncryptionAlgorithm.Cast5, mailboxes, null), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt (EncryptionAlgorithm.Cast5, pubkeys, null), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt (mailboxes, null), "Encrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.Encrypt (pubkeys, null), "Encrypt");

				// Export
				Assert.Throws<ArgumentNullException> (() => ctx.Export ((PgpPublicKeyRingBundle) null), "Export");
				Assert.Throws<ArgumentNullException> (() => ctx.Export ((MailboxAddress[]) null), "Export");
				Assert.Throws<ArgumentNullException> (() => ctx.Export ((PgpPublicKey[]) null), "Export");

				// GetDecryptedStream
				Assert.Throws<ArgumentNullException> (() => ctx.GetDecryptedStream (null), "GetDecryptedStream");

				// GetDigestAlgorithmName
				Assert.Throws<ArgumentOutOfRangeException> (() => ctx.GetDigestAlgorithmName (DigestAlgorithm.None), "GetDigestAlgorithmName");

				// Import
				Assert.Throws<ArgumentNullException> (() => ctx.Import ((Stream) null), "Import");
				Assert.Throws<ArgumentNullException> (() => ctx.Import ((PgpPublicKeyRing) null), "Import");
				Assert.Throws<ArgumentNullException> (() => ctx.Import ((PgpPublicKeyRingBundle) null), "Import");
				Assert.Throws<ArgumentNullException> (() => ctx.Import ((PgpSecretKeyRing) null), "Import");
				Assert.Throws<ArgumentNullException> (() => ctx.Import ((PgpSecretKeyRingBundle) null), "Import");

				// ImportSecretKeys
				Assert.Throws<ArgumentNullException> (() => ctx.ImportSecretKeys (null), "ImportSecretKeys");

				// Sign
				Assert.Throws<ArgumentNullException> (() => ctx.Sign ((MailboxAddress) null, DigestAlgorithm.Sha1, stream), "Sign");
				Assert.Throws<ArgumentNullException> (() => ctx.Sign ((PgpSecretKey) null, DigestAlgorithm.Sha1, stream), "Sign");
				Assert.Throws<ArgumentNullException> (() => ctx.Sign (mailboxes[0], DigestAlgorithm.Sha1, null), "Sign");
				Assert.Throws<ArgumentNullException> (() => ctx.Sign (key, DigestAlgorithm.Sha1, null), "Sign");

				// SignAndEncrypt
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt ((MailboxAddress) null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt ((PgpSecretKey) null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (MailboxAddress[]) null, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (PgpPublicKey[]) null, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentException> (() => ctx.SignAndEncrypt (mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentException> (() => ctx.SignAndEncrypt (key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, null), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, null), "SignAndEncrypt");

				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt ((MailboxAddress) null, DigestAlgorithm.Sha1, mailboxes, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt ((PgpSecretKey) null, DigestAlgorithm.Sha1, pubkeys, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (mailboxes[0], DigestAlgorithm.Sha1, (MailboxAddress[]) null, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (key, DigestAlgorithm.Sha1, (PgpPublicKey[]) null, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentException> (() => ctx.SignAndEncrypt (mailboxes[0], DigestAlgorithm.Sha1, emptyMailboxes, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentException> (() => ctx.SignAndEncrypt (key, DigestAlgorithm.Sha1, emptyPubkeys, stream), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (mailboxes[0], DigestAlgorithm.Sha1, mailboxes, null), "SignAndEncrypt");
				Assert.Throws<ArgumentNullException> (() => ctx.SignAndEncrypt (key, DigestAlgorithm.Sha1, pubkeys, null), "SignAndEncrypt");

				// Supports
				Assert.Throws<ArgumentNullException> (() => ctx.Supports (null), "Supports");

				// Verify
				Assert.Throws<ArgumentNullException> (() => ctx.Verify (null, stream), "Verify");
				Assert.Throws<ArgumentNullException> (() => ctx.Verify (stream, null), "Verify");
			}
		}
Esempio n. 5
0
		public void TestMultipartEncryptedSignAndEncryptALgorithmUsingKeys ()
		{
			var body = new TextPart ("plain") { Text = "This is some cleartext that we'll end up signing and encrypting..." };
			var self = new SecureMailboxAddress ("MimeKit UnitTests", "*****@*****.**", "AB0821A2");
			DigitalSignatureCollection signatures;
			IList<PgpPublicKey> recipients;
			PgpSecretKey signer;

			using (var ctx = new DummyOpenPgpContext ()) {
				recipients = ctx.GetPublicKeys (new [] { self });
				signer = ctx.GetSigningKey (self);
			}

			var encrypted = MultipartEncrypted.SignAndEncrypt (signer, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, recipients, body);

			//using (var file = File.Create ("pgp-signed-encrypted.asc"))
			//	encrypted.WriteTo (file);

			var decrypted = encrypted.Decrypt (out signatures);

			Assert.IsInstanceOf<TextPart> (decrypted, "Decrypted part is not the expected type.");
			Assert.AreEqual (body.Text, ((TextPart) decrypted).Text, "Decrypted content is not the same as the original.");

			Assert.AreEqual (1, signatures.Count, "Verify returned an unexpected number of signatures.");
			foreach (var signature in signatures) {
				try {
					bool valid = signature.Verify ();

					Assert.IsTrue (valid, "Bad signature from {0}", signature.SignerCertificate.Email);
				} catch (DigitalSignatureVerifyException ex) {
					Assert.Fail ("Failed to verify signature: {0}", ex);
				}
			}
		}
Esempio n. 6
0
		public void TestMultipartEncryptedEncryptAlgorithmUsingKeys ()
		{
			var body = new TextPart ("plain") { Text = "This is some cleartext that we'll end up encrypting..." };
			var self = new MailboxAddress ("MimeKit UnitTests", "*****@*****.**");
			IList<PgpPublicKey> recipients;

			using (var ctx = new DummyOpenPgpContext ()) {
				recipients = ctx.GetPublicKeys (new [] { self });
			}

			foreach (EncryptionAlgorithm algorithm in Enum.GetValues (typeof (EncryptionAlgorithm))) {
				if (algorithm == EncryptionAlgorithm.RC240 ||
					algorithm == EncryptionAlgorithm.RC264 || 
					algorithm == EncryptionAlgorithm.RC2128)
					continue;

				var encrypted = MultipartEncrypted.Encrypt (algorithm, recipients, body);

				//using (var file = File.Create ("pgp-encrypted.asc"))
				//	encrypted.WriteTo (file);

				var decrypted = encrypted.Decrypt ();

				Assert.IsInstanceOf<TextPart> (decrypted, "Decrypted part is not the expected type.");
				Assert.AreEqual (body.Text, ((TextPart) decrypted).Text, "Decrypted content is not the same as the original.");
			}
		}
Esempio n. 7
0
        public void TestArgumentExceptions()
        {
            using (var ctx = new DummyOpenPgpContext()) {
                var mailboxes      = new [] { new MailboxAddress("MimeKit UnitTests", "*****@*****.**") };
                var emptyMailboxes = new MailboxAddress[0];
                var pubkeys        = ctx.GetPublicKeys(mailboxes);
                var key            = ctx.GetSigningKey(mailboxes[0]);
                var emptyPubkeys   = new PgpPublicKey[0];
                var stream         = new MemoryStream();

                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpEncrypted((MimeEntityConstructorArgs)null));
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature((MimeEntityConstructorArgs)null));
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature((Stream)null));

                // Accept
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpEncrypted().Accept(null));
                Assert.Throws <ArgumentNullException> (() => new ApplicationPgpSignature(stream).Accept(null));

                // Decrypt
                Assert.Throws <ArgumentNullException> (() => ctx.Decrypt(null), "Decrypt");

                // Encrypt
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, (MailboxAddress[])null, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt((MailboxAddress[])null, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt((PgpPublicKey[])null, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(emptyMailboxes, stream), "Encrypt");
                Assert.Throws <ArgumentException> (() => ctx.Encrypt(emptyPubkeys, stream), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, mailboxes, null), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(EncryptionAlgorithm.Cast5, pubkeys, null), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(mailboxes, null), "Encrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.Encrypt(pubkeys, null), "Encrypt");

                // Export
                Assert.Throws <ArgumentNullException> (() => ctx.Export((PgpPublicKeyRingBundle)null), "Export");
                Assert.Throws <ArgumentNullException> (() => ctx.Export((MailboxAddress[])null), "Export");
                Assert.Throws <ArgumentNullException> (() => ctx.Export((PgpPublicKey[])null), "Export");

                // GetDecryptedStream
                Assert.Throws <ArgumentNullException> (() => ctx.GetDecryptedStream(null), "GetDecryptedStream");

                // GetDigestAlgorithmName
                Assert.Throws <ArgumentOutOfRangeException> (() => ctx.GetDigestAlgorithmName(DigestAlgorithm.None), "GetDigestAlgorithmName");

                // Import
                Assert.Throws <ArgumentNullException> (() => ctx.Import((Stream)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpPublicKeyRing)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpPublicKeyRingBundle)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpSecretKeyRing)null), "Import");
                Assert.Throws <ArgumentNullException> (() => ctx.Import((PgpSecretKeyRingBundle)null), "Import");

                // ImportSecretKeys
                Assert.Throws <ArgumentNullException> (() => ctx.ImportSecretKeys(null), "ImportSecretKeys");

                // Sign
                Assert.Throws <ArgumentNullException> (() => ctx.Sign((MailboxAddress)null, DigestAlgorithm.Sha1, stream), "Sign");
                Assert.Throws <ArgumentNullException> (() => ctx.Sign((PgpSecretKey)null, DigestAlgorithm.Sha1, stream), "Sign");
                Assert.Throws <ArgumentNullException> (() => ctx.Sign(mailboxes[0], DigestAlgorithm.Sha1, null), "Sign");
                Assert.Throws <ArgumentNullException> (() => ctx.Sign(key, DigestAlgorithm.Sha1, null), "Sign");

                // SignAndEncrypt
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (MailboxAddress[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, (PgpPublicKey[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyMailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, emptyPubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, mailboxes, null), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, EncryptionAlgorithm.Cast5, pubkeys, null), "SignAndEncrypt");

                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((MailboxAddress)null, DigestAlgorithm.Sha1, mailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt((PgpSecretKey)null, DigestAlgorithm.Sha1, pubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, (MailboxAddress[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, (PgpPublicKey[])null, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, emptyMailboxes, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, emptyPubkeys, stream), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(mailboxes[0], DigestAlgorithm.Sha1, mailboxes, null), "SignAndEncrypt");
                Assert.Throws <ArgumentNullException> (() => ctx.SignAndEncrypt(key, DigestAlgorithm.Sha1, pubkeys, null), "SignAndEncrypt");

                // Supports
                Assert.Throws <ArgumentNullException> (() => ctx.Supports(null), "Supports");

                // Verify
                Assert.Throws <ArgumentNullException> (() => ctx.Verify(null, stream), "Verify");
                Assert.Throws <ArgumentNullException> (() => ctx.Verify(stream, null), "Verify");
            }
        }