2
2
3
3
const {
4
4
ArrayBufferPrototypeSlice,
5
- FunctionPrototypeCall,
6
5
MathCeil,
7
6
ObjectDefineProperty,
8
- Promise,
9
7
SafeSet,
10
8
} = primordials ;
11
9
@@ -33,7 +31,6 @@ const {
33
31
} = require ( 'internal/errors' ) ;
34
32
35
33
const {
36
- validateFunction,
37
34
validateInt32,
38
35
validateObject,
39
36
validateString,
@@ -57,6 +54,7 @@ const {
57
54
const {
58
55
getArrayBufferOrView,
59
56
getDefaultEncoding,
57
+ jobPromise,
60
58
toBuf,
61
59
kHandle,
62
60
kKeyObject,
@@ -317,22 +315,9 @@ function diffieHellman(options) {
317
315
return statelessDH ( privateKey [ kHandle ] , publicKey [ kHandle ] ) ;
318
316
}
319
317
320
- // The deriveBitsECDH function is part of the Web Crypto API and serves both
318
+ // The ecdhDeriveBits function is part of the Web Crypto API and serves both
321
319
// deriveKeys and deriveBits functions.
322
- function deriveBitsECDH ( name , publicKey , privateKey , callback ) {
323
- validateString ( name , 'name' ) ;
324
- validateObject ( publicKey , 'publicKey' ) ;
325
- validateObject ( privateKey , 'privateKey' ) ;
326
- validateFunction ( callback , 'callback' ) ;
327
- const job = new ECDHBitsJob ( kCryptoJobAsync , name , publicKey , privateKey ) ;
328
- job . ondone = ( error , bits ) => {
329
- if ( error ) return FunctionPrototypeCall ( callback , job , error ) ;
330
- FunctionPrototypeCall ( callback , job , null , bits ) ;
331
- } ;
332
- job . run ( ) ;
333
- }
334
-
335
- async function asyncDeriveBitsECDH ( algorithm , baseKey , length ) {
320
+ async function ecdhDeriveBits ( algorithm , baseKey , length ) {
336
321
const { 'public' : key } = algorithm ;
337
322
338
323
// Null means that we're not asking for a specific number of bits, just
@@ -372,15 +357,11 @@ async function asyncDeriveBitsECDH(algorithm, baseKey, length) {
372
357
throw lazyDOMException ( 'Named curve mismatch' , 'InvalidAccessError' ) ;
373
358
}
374
359
375
- const bits = await new Promise ( ( resolve , reject ) => {
376
- deriveBitsECDH (
377
- key . algorithm . name === 'ECDH' ? baseKey . algorithm . namedCurve : baseKey . algorithm . name ,
378
- key [ kKeyObject ] [ kHandle ] ,
379
- baseKey [ kKeyObject ] [ kHandle ] , ( err , bits ) => {
380
- if ( err ) return reject ( err ) ;
381
- resolve ( bits ) ;
382
- } ) ;
383
- } ) ;
360
+ const bits = await jobPromise ( new ECDHBitsJob (
361
+ kCryptoJobAsync ,
362
+ key . algorithm . name === 'ECDH' ? baseKey . algorithm . namedCurve : baseKey . algorithm . name ,
363
+ key [ kKeyObject ] [ kHandle ] ,
364
+ baseKey [ kKeyObject ] [ kHandle ] ) ) ;
384
365
385
366
// If a length is not specified, return the full derived secret
386
367
if ( length === null )
@@ -407,6 +388,5 @@ module.exports = {
407
388
DiffieHellmanGroup,
408
389
ECDH ,
409
390
diffieHellman,
410
- deriveBitsECDH,
411
- asyncDeriveBitsECDH,
391
+ ecdhDeriveBits,
412
392
} ;
0 commit comments