Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hmac.js to include a better error for undefined key #494

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@
// Init hasher
hasher = this._hasher = new hasher.init();

// Convert string to WordArray, else assume WordArray already
if (typeof key == 'string') {
if (key == null) { // This checks for both undefined and null
throw new Error("Key is undefined or null");
}

// Convert string to WordArray, else assume WordArray already
if (typeof key == "string") {
key = Utf8.parse(key);
}
}

// Determine if the key is missing any values - most notably, the 'sigBytes' property
if (!Object.prototype.hasOwnProperty.call(key, "sigBytes")) {
// throw error
throw new Error("Key missing 'sigBytes' property");
}

// Shortcuts
var hasherBlockSize = hasher.blockSize;
Expand Down