@@ -73,7 +73,7 @@ function commonCbcEncryptFN(size) {
73
73
return helpers . subtleCrypto . encrypt ( alg , key , pdata ) ;
74
74
} ) ;
75
75
promise = promise . then ( function ( cdata ) {
76
- cdata = new Buffer ( cdata ) ;
76
+ cdata = Buffer . from ( cdata ) ;
77
77
return cdata ;
78
78
} ) ;
79
79
@@ -163,7 +163,7 @@ function commonCbcDecryptFN(size) {
163
163
return helpers . subtleCrypto . decrypt ( alg , key , cdata ) ;
164
164
} ) ;
165
165
promise = promise . then ( function ( pdata ) {
166
- pdata = new Buffer ( pdata ) ;
166
+ pdata = Buffer . from ( pdata ) ;
167
167
return pdata ;
168
168
} ) ;
169
169
@@ -215,8 +215,8 @@ function cbcHmacEncryptFN(size) {
215
215
216
216
var eKey = key . slice ( size / 8 ) ,
217
217
iKey = key . slice ( 0 , size / 8 ) ,
218
- iv = props . iv || new Buffer ( 0 ) ,
219
- adata = props . aad || props . adata || new Buffer ( 0 ) ;
218
+ iv = props . iv || Buffer . alloc ( 0 ) ,
219
+ adata = props . aad || props . adata || Buffer . alloc ( 0 ) ;
220
220
221
221
// STEP 1 -- Encrypt
222
222
var promise = commonEncrypt ( eKey , pdata , iv ) ;
@@ -262,9 +262,9 @@ function cbcHmacDecryptFN(size) {
262
262
263
263
var eKey = key . slice ( size / 8 ) ,
264
264
iKey = key . slice ( 0 , size / 8 ) ,
265
- iv = props . iv || new Buffer ( 0 ) ,
266
- adata = props . aad || props . adata || new Buffer ( 0 ) ,
267
- tag = props . tag || props . mac || new Buffer ( 0 ) ;
265
+ iv = props . iv || Buffer . alloc ( 0 ) ,
266
+ adata = props . aad || props . adata || Buffer . alloc ( 0 ) ,
267
+ tag = props . tag || props . mac || Buffer . alloc ( 0 ) ;
268
268
269
269
var promise = Promise . resolve ( ) ;
270
270
@@ -299,9 +299,9 @@ function cbcHmacDecryptFN(size) {
299
299
} ;
300
300
}
301
301
302
- var EncryptionLabel = new Buffer ( "Encryption" , "utf8" ) ;
303
- var IntegrityLabel = new Buffer ( "Integrity" , "utf8" ) ;
304
- var DotLabel = new Buffer ( "." , "utf8" ) ;
302
+ var EncryptionLabel = Buffer . from ( "Encryption" , "utf8" ) ;
303
+ var IntegrityLabel = Buffer . from ( "Integrity" , "utf8" ) ;
304
+ var DotLabel = Buffer . from ( "." , "utf8" ) ;
305
305
306
306
function generateCek ( masterKey , alg , epu , epv ) {
307
307
var masterSize = masterKey . length * 8 ;
@@ -313,7 +313,7 @@ function generateCek(masterKey, alg, epu, epv) {
313
313
helpers . int32ToBuffer ( 1 ) ,
314
314
masterKey ,
315
315
helpers . int32ToBuffer ( cekSize ) ,
316
- new Buffer ( alg , "utf8" ) ,
316
+ Buffer . from ( alg , "utf8" ) ,
317
317
epu ,
318
318
epv ,
319
319
EncryptionLabel
@@ -342,7 +342,7 @@ function generateCik(masterKey, alg, epu, epv) {
342
342
helpers . int32ToBuffer ( 1 ) ,
343
343
masterKey ,
344
344
helpers . int32ToBuffer ( cikSize ) ,
345
- new Buffer ( alg , "utf8" ) ,
345
+ Buffer . from ( alg , "utf8" ) ,
346
346
epu ,
347
347
epv ,
348
348
IntegrityLabel
@@ -367,9 +367,9 @@ function concatKdfCbcHmacEncryptFN(size, alg) {
367
367
return function ( key , pdata , props ) {
368
368
var epu = props . epu || helpers . int32ToBuffer ( 0 ) ,
369
369
epv = props . epv || helpers . int32ToBuffer ( 0 ) ,
370
- iv = props . iv || new Buffer ( 0 ) ,
371
- adata = props . aad || props . adata || new Buffer ( 0 ) ,
372
- kdata = props . kdata || new Buffer ( 0 ) ;
370
+ iv = props . iv || Buffer . alloc ( 0 ) ,
371
+ adata = props . aad || props . adata || Buffer . alloc ( 0 ) ,
372
+ kdata = props . kdata || Buffer . alloc ( 0 ) ;
373
373
374
374
// Pre Step 1 -- Generate Keys
375
375
var promises = [
@@ -394,11 +394,11 @@ function concatKdfCbcHmacEncryptFN(size, alg) {
394
394
var mdata = Buffer . concat ( [
395
395
adata ,
396
396
DotLabel ,
397
- new Buffer ( kdata ) ,
397
+ Buffer . from ( kdata ) ,
398
398
DotLabel ,
399
- new Buffer ( util . base64url . encode ( iv ) , "utf8" ) ,
399
+ Buffer . from ( util . base64url . encode ( iv ) , "utf8" ) ,
400
400
DotLabel ,
401
- new Buffer ( util . base64url . encode ( cdata ) , "utf8" )
401
+ Buffer . from ( util . base64url . encode ( cdata ) , "utf8" )
402
402
] ) ;
403
403
return Promise . all ( [
404
404
Promise . resolve ( cdata ) ,
@@ -422,10 +422,10 @@ function concatKdfCbcHmacDecryptFN(size, alg) {
422
422
return function ( key , cdata , props ) {
423
423
var epu = props . epu || helpers . int32ToBuffer ( 0 ) ,
424
424
epv = props . epv || helpers . int32ToBuffer ( 0 ) ,
425
- iv = props . iv || new Buffer ( 0 ) ,
426
- adata = props . aad || props . adata || new Buffer ( 0 ) ,
427
- kdata = props . kdata || new Buffer ( 0 ) ,
428
- tag = props . tag || props . mac || new Buffer ( 0 ) ;
425
+ iv = props . iv || Buffer . alloc ( 0 ) ,
426
+ adata = props . aad || props . adata || Buffer . alloc ( 0 ) ,
427
+ kdata = props . kdata || Buffer . alloc ( 0 ) ,
428
+ tag = props . tag || props . mac || Buffer . alloc ( 0 ) ;
429
429
430
430
// Pre Step 1 -- Generate Keys
431
431
var promises = [
@@ -447,11 +447,11 @@ function concatKdfCbcHmacDecryptFN(size, alg) {
447
447
var mdata = Buffer . concat ( [
448
448
adata ,
449
449
DotLabel ,
450
- new Buffer ( kdata ) ,
450
+ Buffer . from ( kdata ) ,
451
451
DotLabel ,
452
- new Buffer ( util . base64url . encode ( iv ) , "utf8" ) ,
452
+ Buffer . from ( util . base64url . encode ( iv ) , "utf8" ) ,
453
453
DotLabel ,
454
- new Buffer ( util . base64url . encode ( cdata ) , "utf8" )
454
+ Buffer . from ( util . base64url . encode ( cdata ) , "utf8" )
455
455
] ) ;
456
456
457
457
try {
0 commit comments