@@ -16,6 +16,7 @@ const {
1616 ObjectKeys,
1717 ObjectPrototypeHasOwnProperty,
1818 Promise,
19+ SafeSet,
1920 StringPrototypeToUpperCase,
2021 Symbol,
2122 TypedArrayPrototypeGetBuffer,
@@ -757,9 +758,26 @@ const kKeyOps = {
757758 deriveBits : 8 ,
758759} ;
759760
761+ const allowedGroups = [
762+ new SafeSet ( [ 'sign' , 'verify' ] ) ,
763+ new SafeSet ( [ 'encrypt' , 'decrypt' ] ) ,
764+ new SafeSet ( [ 'wrapKey' , 'unwrapKey' ] ) ,
765+ ] ;
766+
760767function validateKeyOps ( keyOps , usagesSet ) {
761768 if ( keyOps === undefined ) return ;
762769 validateArray ( keyOps , 'keyData.key_ops' ) ;
770+ const keyOpsSet = new SafeSet ( keyOps ) ;
771+ const isValidCombo = allowedGroups . some ( ( group ) => {
772+ return [ ...keyOpsSet ] . every ( ( op ) => group . has ( op ) ) ;
773+ } ) ;
774+ if ( ! isValidCombo && keyOpsSet . size > 1 ) {
775+ process . emitWarning (
776+ 'Using unrelated key_ops combinations (RFC7517 section 4.3) is deprecated and will throw in a future version.' ,
777+ 'DeprecationWarning' ,
778+ ) ;
779+ }
780+
763781 let flags = 0 ;
764782 for ( let n = 0 ; n < keyOps . length ; n ++ ) {
765783 const op = keyOps [ n ] ;
@@ -771,10 +789,6 @@ function validateKeyOps(keyOps, usagesSet) {
771789 if ( flags & ( 1 << op_flag ) )
772790 throw lazyDOMException ( 'Duplicate key operation' , 'DataError' ) ;
773791 flags |= ( 1 << op_flag ) ;
774-
775- // TODO(@jasnell): RFC7517 section 4.3 strong recommends validating
776- // key usage combinations. Specifically, it says that unrelated key
777- // ops SHOULD NOT be used together. We're not yet validating that here.
778792 }
779793
780794 if ( usagesSet !== undefined ) {
0 commit comments