Skip to content

Commit bc362b2

Browse files
committed
fixup! lib,crypto: rewire CryptoKey on the native class
1 parent c4f74ad commit bc362b2

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

lib/internal/crypto/keys.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,10 @@ const {
897897
return [CryptoKey, InternalCryptoKey];
898898
});
899899

900-
// The helpers below return a CryptoKey's raw internal slot value,
900+
// The helpers below return a CryptoKey's internal slot value,
901901
// populating the per-instance cache on first access via a single
902-
// native call. The public `algorithm` / `usages` getters on
902+
// native call. The public `type` getter converts the native enum to
903+
// the Web Crypto string. The public `algorithm` / `usages` getters on
903904
// `CryptoKey.prototype` further clone their slot before returning.
904905

905906
/**
@@ -908,7 +909,16 @@ const {
908909
* @returns {'secret' | 'public' | 'private'}
909910
*/
910911
function getCryptoKeyType(key) {
911-
return getSlots(key)[kSlotType];
912+
switch (getSlots(key)[kSlotType]) {
913+
case kKeyTypeSecret: return 'secret';
914+
case kKeyTypePublic: return 'public';
915+
case kKeyTypePrivate: return 'private';
916+
default: {
917+
// It is not possible to get here because all possible cases are handled above.
918+
const assert = require('internal/assert');
919+
assert.fail('Unreachable code');
920+
}
921+
}
912922
}
913923

914924
/**

0 commit comments

Comments
 (0)