Skip to content

Commit

Permalink
Fixed S/MIME unit tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jstedfast committed Oct 21, 2017
1 parent 902de16 commit f14bba0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions MimeKit/Cryptography/SecureMimeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit f14bba0

Please sign in to comment.