From f14bba09cdfba98b1a960329199ea6c4c6ca2ea2 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Sat, 21 Oct 2017 09:03:43 -0400 Subject: [PATCH] Fixed S/MIME unit tests It seems that PR #337 may be wrong as it causes a CastException because identifier.Parameters is a DerInteger rather than a DerSequence. Restored my old logic for cases where identifier.Parameters is not a DerSequence. --- MimeKit/Cryptography/SecureMimeContext.cs | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/MimeKit/Cryptography/SecureMimeContext.cs b/MimeKit/Cryptography/SecureMimeContext.cs index d001c55bf0..6dda8270b2 100644 --- a/MimeKit/Cryptography/SecureMimeContext.cs +++ b/MimeKit/Cryptography/SecureMimeContext.cs @@ -892,14 +892,25 @@ internal protected static bool TryGetEncryptionAlgorithm (AlgorithmIdentifier id } if (identifier.Algorithm.Id == CmsEnvelopedGenerator.RC2Cbc) { - var param = (DerSequence) identifier.Parameters; - var version = (DerInteger) param[0]; - int bits = version.Value.IntValue; - - switch (bits) { - case 58: algorithm = EncryptionAlgorithm.RC2128; return true; - case 120: algorithm = EncryptionAlgorithm.RC264; return true; - case 160: algorithm = EncryptionAlgorithm.RC240; return true; + if (identifier.Parameters is DerSequence) { + var param = (DerSequence) identifier.Parameters; + var version = (DerInteger) param[0]; + int bits = version.Value.IntValue; + + switch (bits) { + case 58: algorithm = EncryptionAlgorithm.RC2128; return true; + case 120: algorithm = EncryptionAlgorithm.RC264; return true; + case 160: algorithm = EncryptionAlgorithm.RC240; return true; + } + } else { + var param = (DerInteger) identifier.Parameters; + int bits = param.Value.IntValue; + + switch (bits) { + case 128: algorithm = EncryptionAlgorithm.RC2128; return true; + case 64: algorithm = EncryptionAlgorithm.RC264; return true; + case 40: algorithm = EncryptionAlgorithm.RC240; return true; + } } }