MimeKit.Cryptography.TemporarySecureMimeContext.GetCmsSigner C# (CSharp) Method

GetCmsSigner() protected method

Gets the CmsSigner for the specified mailbox.

Constructs a CmsSigner with the appropriate signing certificate for the specified mailbox.

If the mailbox is a SecureMailboxAddress, the SecureMailboxAddress.Fingerprint property will be used instead of the mailbox address for database lookups.

/// A certificate for the specified could not be found. ///
protected GetCmsSigner ( MimeKit.MailboxAddress mailbox, DigestAlgorithm digestAlgo ) : CmsSigner
mailbox MimeKit.MailboxAddress The mailbox.
digestAlgo DigestAlgorithm The preferred digest algorithm.
return CmsSigner
		protected override CmsSigner GetCmsSigner (MailboxAddress mailbox, DigestAlgorithm digestAlgo)
		{
			var now = DateTime.UtcNow;

			foreach (var certificate in certificates) {
				AsymmetricKeyParameter key;

				if (certificate.NotBefore > now || certificate.NotAfter < now)
					continue;

				var keyUsage = certificate.GetKeyUsageFlags ();
				if (keyUsage != 0 && (keyUsage & SecureMimeContext.DigitalSignatureKeyUsageFlags) == 0)
					continue;

				if (!keys.TryGetValue (certificate, out key))
					continue;

				var address = certificate.GetSubjectEmailAddress ();

				if (address.Equals (mailbox.Address, StringComparison.OrdinalIgnoreCase)) {
					var signer = new CmsSigner (certificate, key);
					signer.DigestAlgorithm = digestAlgo;
					return signer;
				}
			}

			throw new CertificateNotFoundException (mailbox, "A valid signing certificate could not be found.");
		}