Skip to content

Commit 9f2f813

Browse files
committed
Fix: only honor isPrivate if it is actually a Boolean
1 parent 89325da commit 9f2f813

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/jwk/basekey.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ var JWKBaseKeyObject = function(kty, ks, props, cfg) {
357357
result = merge(result,
358358
json.base,
359359
json.public,
360-
(isPrivate) ? json.private : {},
360+
("boolean" === typeof isPrivate && isPrivate) ? json.private : {},
361361
json.extra);
362362
result = omit(result, excluded || []);
363363

@@ -417,7 +417,7 @@ var JWKBaseKeyObject = function(kty, ks, props, cfg) {
417417
result = merge(result,
418418
json.base,
419419
keys.public,
420-
(isPrivate) ? keys.private : {},
420+
("boolean" === typeof isPrivate && isPrivate) ? keys.private : {},
421421
json.extra);
422422
result = omit(result, (excluded || []).concat("length"));
423423

test/jwk/basekey-test.js

+25
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,31 @@ describe("jwk/basekey", function() {
629629
"alg": "A128GCM"
630630
});
631631
});
632+
it("ignores isPrivate if not a Boolean", function() {
633+
var props = {
634+
kid: "somevalue",
635+
pub: "Lc3EY3_96tfej0F7Afa0TQ",
636+
prv: "SBh6LBt1DBTeyHTvwDgSjg",
637+
use: "enc",
638+
alg: "A128GCM"
639+
};
640+
var inst = createInstance(props);
641+
642+
assert.deepEqual(inst.toObject("42"), {
643+
"kty": "DUMMY",
644+
"kid": "somevalue",
645+
"pub": util.base64url.decode("Lc3EY3_96tfej0F7Afa0TQ"),
646+
"use": "enc",
647+
"alg": "A128GCM"
648+
});
649+
assert.deepEqual(inst.toJSON("42"), {
650+
"kty": "DUMMY",
651+
"kid": "somevalue",
652+
"pub": "Lc3EY3_96tfej0F7Afa0TQ",
653+
"use": "enc",
654+
"alg": "A128GCM"
655+
});
656+
});
632657
});
633658

634659
describe("thumbprints", function() {

0 commit comments

Comments
 (0)