{"record":{"id":"99eb7b53771fbd9a","repo":"jstedfast/MailKit","slug":"data","errorCode":null,"errorMessage":"data","messagePattern":"data","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/KeyedHashAlgorithm.cs","lineNumber":75,"sourceCode":"\n\t\t/// <summary>\n\t\t/// Computes the hash code for the buffer.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Computes the hash code for the buffer.\n\t\t/// </remarks>\n\t\t/// <returns>The computed hash code.</returns>\n\t\t/// <param name=\"buffer\">The buffer.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"buffer\"/> is <c>null</c>.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ObjectDisposedException\">\n\t\t/// The keyed hash algorithm context has been disposed.\n\t\t/// </exception>\n\t\tpublic byte[] ComputeHash (byte[] buffer)\n\t\t{\n\t\t\tif (buffer == null)\n\t\t\t\tthrow new ArgumentNullException (\"data\");\n\n\t\t\thmac.Append (CryptographicBuffer.CreateFromByteArray (buffer));\n\t\t\tvar value = hmac.GetValueAndReset ();\n\t\t\tbyte[] hash;\n\n\t\t\tCryptographicBuffer.CopyToByteArray (value, out hash);\n\n\t\t\treturn hash;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Releases all resource used by the <see cref=\"MailKit.Security.KeyedHashAlgorithm\"/> object.\n\t\t/// </summary>\n\t\t/// <remarks>Call <see cref=\"Dispose()\"/> when you are finished using the <see cref=\"MailKit.Security.KeyedHashAlgorithm\"/>. The\n\t\t/// <see cref=\"Dispose()\"/> method leaves the <see cref=\"MailKit.Security.KeyedHashAlgorithm\"/> in an unusable state. After calling\n\t\t/// <see cref=\"Dispose()\"/>, you must release all references to the <see cref=\"MailKit.Security.KeyedHashAlgorithm\"/> so the\n\t\t/// garbage collector can reclaim the memory that the <see cref=\"MailKit.Security.KeyedHashAlgorithm\"/> was occupying.</remarks>\n\t\tpublic void Dispose ()","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/KeyedHashAlgorithm.cs#L57-L93","documentation":"MailKit's WinRT-based KeyedHashAlgorithm wrapper (used for CRAM-MD5/NTLM on UWP) throws ArgumentNullException with parameter name \"data\" when ComputeHash is called with a null buffer. The buffer must be a real byte array because it is converted into an IBuffer via CryptographicBuffer.CreateFromByteArray before hashing.","triggerScenarios":"Calling ComputeHash((byte[]) null) on a disposed-or-valid keyed hash context — the null check fires before any use of the underlying hmac object.","commonSituations":"Hashing data read from a stream or SASL challenge where the byte-array conversion step returned null; passing an uninitialized field; a custom SASL mechanism that passes the raw (null) challenge through.","solutions":["Ensure the input byte array is non-null before calling ComputeHash (e.g., use ?? Array.Empty<byte>() if empty input is legal for your protocol).","Check that the code producing the buffer (stream read, challenge decode) succeeded and did not return null.","Note this is a null check, not a disposed-check — if you also see ObjectDisposedException, check disposal separately."],"exampleFix":"// before\nbyte[] hmac = hasher.ComputeHash(challengeBytes); // challengeBytes may be null\n\n// after\nbyte[] hmac = hasher.ComputeHash(challengeBytes ?? Array.Empty<byte>());","handlingStrategy":"validation","validationCode":"if (buffer == null) throw new InvalidOperationException(\"challenge bytes missing\");\nbyte[] hash = hasher.ComputeHash(buffer);","typeGuard":"static bool HasData(byte[] b) => b != null && b.Length > 0;","tryCatchPattern":"try {\n    var hash = hasher.ComputeHash(buffer);\n} catch (ArgumentNullException) {\n    // null input: regenerate the buffer or abort the auth exchange\n}","preventionTips":["Ensure stream reads and challenge decoders never return null (use Array.Empty as sentinel).","Check return values of any byte-array-producing helper before hashing.","Dispose keyed-hash contexts promptly so disposal-state errors don't get conflated with null inputs."],"tags":["mailkit","security","hmac","null-argument"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}