{"record":{"id":"f23db8a4b12472d6","repo":"jstedfast/MailKit","slug":"value","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/HMACMD5.cs","lineNumber":65,"sourceCode":"\t\t{\n\t\t\tDispose (false);\n\t\t}\n\n\t\tpublic byte[] Hash\n\t\t{\n\t\t\tget {\n\t\t\t\tif (hashValue == null)\n\t\t\t\t\tthrow new InvalidOperationException (\"No hash value computed.\");\n\n\t\t\t\treturn hashValue;\n\t\t\t}\n\t\t}\n\n\t\tpublic byte[] Key {\n\t\t\tget { return key; }\n\t\t\tset {\n\t\t\t\tif (value == null)\n\t\t\t\t\tthrow new ArgumentNullException (nameof (value));\n\n\t\t\t\tif (key != null)\n\t\t\t\t\tArray.Clear (key, 0, key.Length);\n\n\t\t\t\tkey = value;\n\t\t\t\tInitialize ();\n\t\t\t}\n\t\t}\n\n\t\tvoid HashCore (byte[] block, int offset, int size)\n\t\t{\n\t\t\thash.BlockUpdate (block, offset, size);\n\t\t}\n\n\t\tbyte[] HashFinal ()\n\t\t{\n\t\t\tvar value = new byte[hash.GetMacSize ()];\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/HMACMD5.cs#L47-L83","documentation":"Guard in the HMACMD5.Key property setter: assigning a null key is invalid because the HMAC algorithm requires key material; the setter rejects null with ArgumentNullException, clears any previous key otherwise, and re-initializes the hash.","triggerScenarios":"Assigning null to hmac.Key, typically when the key came from an unset config value or a failed credential lookup.","commonSituations":"NTLM code paths where the session key derivation silently produced null (e.g. missing NTLM credentials).","solutions":["Ensure the key byte[] is non-null before assignment","Guard the credential/key derivation so it cannot yield null","Catch ArgumentNullException and surface a missing-credentials error"],"exampleFix":"// before\nhmac.Key = sessionKey; // may be null\n// after\nif (sessionKey != null)\n\thmac.Key = sessionKey;","handlingStrategy":"validation","validationCode":"if (key == null) throw new ArgumentException(\"HMAC key must not be null\");","typeGuard":"bool HasKey(byte[] k) => k != null && k.Length > 0;","tryCatchPattern":"try { hmac.Key = key; } catch (ArgumentNullException) { /* missing credentials */ }","preventionTips":["Validate credential derivation before constructing HMAC","Fail early on missing NTLM credentials","Treat null keys as config errors, not empty hashes"],"tags":["csharp","hmac","argument-null"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}