File tree Expand file tree Collapse file tree 3 files changed +36
-8
lines changed Expand file tree Collapse file tree 3 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -206,30 +206,33 @@ function validateMaxBufferLength(data, name) {
206206  } 
207207} 
208208
209- function  normalizeAlgorithm ( algorithm ,   label   =   'algorithm' )  { 
209+ function  normalizeAlgorithm ( algorithm )  { 
210210  if  ( algorithm  !=  null )  { 
211211    if  ( typeof  algorithm  ===  'string' ) 
212212      algorithm  =  {  name : algorithm  } ; 
213213
214214    if  ( typeof  algorithm  ===  'object' )  { 
215215      const  {  name }  =  algorithm ; 
216-       let  hash ; 
217216      if  ( typeof  name  !==  'string'  || 
218217          ! ArrayPrototypeIncludes ( 
219218            kAlgorithmsKeys , 
220219            StringPrototypeToLowerCase ( name ) ) )  { 
221220        throw  lazyDOMException ( 'Unrecognized name.' ,  'NotSupportedError' ) ; 
222221      } 
223-       if  ( algorithm . hash  !==  undefined )  { 
224-         hash  =  normalizeAlgorithm ( algorithm . hash ,  'algorithm.hash' ) ; 
222+       let  {  hash }  =  algorithm ; 
223+       if  ( hash  !==  undefined )  { 
224+         hash  =  normalizeAlgorithm ( hash ) ; 
225225        if  ( ! ArrayPrototypeIncludes ( kHashTypes ,  hash . name ) ) 
226226          throw  lazyDOMException ( 'Unrecognized name.' ,  'NotSupportedError' ) ; 
227227      } 
228-       return  { 
228+       const   normalized   =  { 
229229        ...algorithm , 
230230        name : kAlgorithms [ StringPrototypeToLowerCase ( name ) ] , 
231-         hash, 
232231      } ; 
232+       if  ( hash )  { 
233+         normalized . hash  =  hash ; 
234+       } 
235+       return  normalized ; 
233236    } 
234237  } 
235238  throw  lazyDOMException ( 'Unrecognized name.' ,  'NotSupportedError' ) ; 
Original file line number Diff line number Diff line change @@ -587,10 +587,10 @@ async function unwrapKey(
587587  extractable , 
588588  keyUsages )  { 
589589  wrappedKey  =  getArrayBufferOrView ( wrappedKey ,  'wrappedKey' ) ; 
590- 
590+    unwrapAlgo   =   normalizeAlgorithm ( unwrapAlgo ) ; 
591591  let  keyData  =  await  cipherOrWrap ( 
592592    kWebCryptoCipherDecrypt , 
593-     normalizeAlgorithm ( unwrapAlgo ) , 
593+     unwrapAlgo , 
594594    unwrappingKey , 
595595    wrappedKey , 
596596    'unwrapKey' ) ; 
Original file line number Diff line number Diff line change 1+ // Flags: --expose-internals 
2+ 'use strict' ; 
3+ 
4+ const  common  =  require ( '../common' ) ; 
5+ if  ( ! common . hasCrypto ) 
6+   common . skip ( 'missing crypto' ) ; 
7+ 
8+ const  assert  =  require ( 'assert' ) ; 
9+ 
10+ const  { 
11+   normalizeAlgorithm, 
12+ }  =  require ( 'internal/crypto/util' ) ; 
13+ 
14+ { 
15+   // Check that normalizeAlgorithm does not add an undefined hash property. 
16+   assert . strictEqual ( 'hash'  in  normalizeAlgorithm ( {  name : 'ECDH'  } ) ,  false ) ; 
17+   assert . strictEqual ( 'hash'  in  normalizeAlgorithm ( 'ECDH' ) ,  false ) ; 
18+ } 
19+ 
20+ { 
21+   // Check that normalizeAlgorithm does not mutate object inputs. 
22+   const  algorithm  =  {  name : 'ECDH' ,  hash : 'SHA-256'  } ; 
23+   assert . strictEqual ( normalizeAlgorithm ( algorithm )  !==  algorithm ,  true ) ; 
24+   assert . deepStrictEqual ( algorithm ,  {  name : 'ECDH' ,  hash : 'SHA-256'  } ) ; 
25+ } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments