Skip to content

Commit

Permalink
Return DBNull.Value instead of null in SQL value encoding methods
Browse files Browse the repository at this point in the history
Better fix for issue #286
  • Loading branch information
jstedfast committed Mar 9, 2017
1 parent 0737089 commit 69102d2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions MimeKit/Cryptography/X509CertificateDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ AsymmetricKeyParameter DecodePrivateKey (DbDataReader reader, int column, ref by
return DecryptAsymmetricKeyParameter (buffer, nread);
}

byte[] EncodePrivateKey (AsymmetricKeyParameter key)
object EncodePrivateKey (AsymmetricKeyParameter key)
{
return key != null ? EncryptAsymmetricKeyParameter (key) : null;
return key != null ? (object) EncryptAsymmetricKeyParameter (key) : DBNull.Value;
}

static EncryptionAlgorithm[] DecodeEncryptionAlgorithms (DbDataReader reader, int column)
Expand All @@ -241,9 +241,6 @@ static EncryptionAlgorithm[] DecodeEncryptionAlgorithms (DbDataReader reader, in
var algorithms = new List<EncryptionAlgorithm> ();
var values = reader.GetString (column);

if (values.Equals ("None", StringComparison.OrdinalIgnoreCase))
return null;

foreach (var token in values.Split (new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)) {
EncryptionAlgorithm algorithm;

Expand All @@ -263,10 +260,10 @@ static EncryptionAlgorithm[] DecodeEncryptionAlgorithms (DbDataReader reader, in
return algorithms.ToArray ();
}

static string EncodeEncryptionAlgorithms (EncryptionAlgorithm[] algorithms)
static object EncodeEncryptionAlgorithms (EncryptionAlgorithm[] algorithms)
{
if (algorithms == null || algorithms.Length == 0)
return "None";
return DBNull.Value;

var tokens = new string[algorithms.Length];
for (int i = 0; i < algorithms.Length; i++)
Expand Down

0 comments on commit 69102d2

Please sign in to comment.