@@ -127,41 +127,25 @@ describe("Libsodium", () => {
127127      } ; 
128128
129129      // 8 bytes 
130-       await  Argon2id . execute ( password ,  fromHex ( "aabbccddeeff0011" ) ,  options ) 
131-         . then ( ( )  =>  { 
132-           throw  new  Error ( "Argon2id with invalid salt length must not resolve" ) ; 
133-         } ) 
134-         . catch ( ( e )  =>  { 
135-           expect ( e ) . toMatch ( / i n v a l i d   s a l t   l e n g t h / ) ; 
136-         } ) ; 
130+       await  expectAsync ( 
131+         Argon2id . execute ( password ,  fromHex ( "aabbccddeeff0011" ) ,  options ) , 
132+       ) . toBeRejectedWithError ( / i n v a l i d   s a l t   l e n g t h / ) ; 
137133      // 15 bytes 
138-       await  Argon2id . execute ( password ,  fromHex ( "aabbccddeeff001122334455667788" ) ,  options ) 
139-         . then ( ( )  =>  { 
140-           throw  new  Error ( "Argon2id with invalid salt length must not resolve" ) ; 
141-         } ) 
142-         . catch ( ( e )  =>  { 
143-           expect ( e ) . toMatch ( / i n v a l i d   s a l t   l e n g t h / ) ; 
144-         } ) ; 
134+       await  expectAsync ( 
135+         Argon2id . execute ( password ,  fromHex ( "aabbccddeeff001122334455667788" ) ,  options ) , 
136+       ) . toBeRejectedWithError ( / i n v a l i d   s a l t   l e n g t h / ) ; 
145137      // 17 bytes 
146-       await  Argon2id . execute ( password ,  fromHex ( "aabbccddeeff00112233445566778899aa" ) ,  options ) 
147-         . then ( ( )  =>  { 
148-           throw  new  Error ( "Argon2id with invalid salt length must not resolve" ) ; 
149-         } ) 
150-         . catch ( ( e )  =>  { 
151-           expect ( e ) . toMatch ( / i n v a l i d   s a l t   l e n g t h / ) ; 
152-         } ) ; 
138+       await  expectAsync ( 
139+         Argon2id . execute ( password ,  fromHex ( "aabbccddeeff00112233445566778899aa" ) ,  options ) , 
140+       ) . toBeRejectedWithError ( / i n v a l i d   s a l t   l e n g t h / ) ; 
153141      // 32 bytes 
154-       await  Argon2id . execute ( 
155-         password , 
156-         fromHex ( "aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899" ) , 
157-         options , 
158-       ) 
159-         . then ( ( )  =>  { 
160-           throw  new  Error ( "Argon2id with invalid salt length must not resolve" ) ; 
161-         } ) 
162-         . catch ( ( e )  =>  { 
163-           expect ( e ) . toMatch ( / i n v a l i d   s a l t   l e n g t h / ) ; 
164-         } ) ; 
142+       await  expectAsync ( 
143+         Argon2id . execute ( 
144+           password , 
145+           fromHex ( "aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899" ) , 
146+           options , 
147+         ) , 
148+       ) . toBeRejectedWithError ( / i n v a l i d   s a l t   l e n g t h / ) ; 
165149    } ) ; 
166150  } ) ; 
167151
@@ -233,25 +217,13 @@ describe("Libsodium", () => {
233217      { 
234218        // seed too short 
235219        const  seed  =  fromHex ( "43a9c17ccbb0e767ea29ce1f10813afde5f1e0a7a504e89b4d2cc2b952b8e0" ) ; 
236-         await  Ed25519 . makeKeypair ( seed ) 
237-           . then ( ( )  =>  { 
238-             throw  new  Error ( "promise must not resolve" ) ; 
239-           } ) 
240-           . catch ( ( error )  =>  { 
241-             expect ( error . message ) . toContain ( "key of length 32 expected" ) ; 
242-           } ) ; 
220+         await  expectAsync ( Ed25519 . makeKeypair ( seed ) ) . toBeRejectedWithError ( / k e y   o f   l e n g t h   3 2   e x p e c t e d / ) ; 
243221      } 
244222
245223      { 
246224        // seed too long 
247225        const  seed  =  fromHex ( "43a9c17ccbb0e767ea29ce1f10813afde5f1e0a7a504e89b4d2cc2b952b8e0b9aa" ) ; 
248-         await  Ed25519 . makeKeypair ( seed ) 
249-           . then ( ( )  =>  { 
250-             throw  new  Error ( "promise must not resolve" ) ; 
251-           } ) 
252-           . catch ( ( error )  =>  { 
253-             expect ( error . message ) . toContain ( "key of length 32 expected" ) ; 
254-           } ) ; 
226+         await  expectAsync ( Ed25519 . makeKeypair ( seed ) ) . toBeRejectedWithError ( / k e y   o f   l e n g t h   3 2   e x p e c t e d / ) ; 
255227      } 
256228    } ) ; 
257229
@@ -421,48 +393,32 @@ describe("Libsodium", () => {
421393      { 
422394        // empty 
423395        const  key  =  fromHex ( "" ) ; 
424-         await  Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) 
425-           . then ( ( )  =>  { 
426-             throw  new  Error ( "encryption must not succeed" ) ; 
427-           } ) 
428-           . catch ( ( error )  =>  { 
429-             expect ( error ) . toMatch ( / k e y ,   g o t   l e n g t h = 0 / ) ; 
430-           } ) ; 
396+         await  expectAsync ( Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) ) . toBeRejectedWithError ( 
397+           / k e y ,   g o t   l e n g t h = 0 / , 
398+         ) ; 
431399      } 
432400      { 
433401        // 31 bytes 
434402        const  key  =  fromHex ( "1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916" ) ; 
435-         await  Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) 
436-           . then ( ( )  =>  { 
437-             throw  new  Error ( "encryption must not succeed" ) ; 
438-           } ) 
439-           . catch ( ( error )  =>  { 
440-             expect ( error ) . toMatch ( / k e y ,   g o t   l e n g t h = 3 1 / ) ; 
441-           } ) ; 
403+         await  expectAsync ( Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) ) . toBeRejectedWithError ( 
404+           / k e y ,   g o t   l e n g t h = 3 1 / , 
405+         ) ; 
442406      } 
443407      { 
444408        // 33 bytes 
445409        const  key  =  fromHex ( "1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916d8aa" ) ; 
446-         await  Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) 
447-           . then ( ( )  =>  { 
448-             throw  new  Error ( "encryption must not succeed" ) ; 
449-           } ) 
450-           . catch ( ( error )  =>  { 
451-             expect ( error ) . toMatch ( / k e y ,   g o t   l e n g t h = 3 3 / ) ; 
452-           } ) ; 
410+         await  expectAsync ( Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) ) . toBeRejectedWithError ( 
411+           / k e y ,   g o t   l e n g t h = 3 3 / , 
412+         ) ; 
453413      } 
454414      { 
455415        // 64 bytes 
456416        const  key  =  fromHex ( 
457417          "1324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916d81324cdddc4b94e625bbabcac862c9429ba011e2184a1ccad60e7c3f6ff4916d8" , 
458418        ) ; 
459-         await  Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) 
460-           . then ( ( )  =>  { 
461-             throw  new  Error ( "encryption must not succeed" ) ; 
462-           } ) 
463-           . catch ( ( error )  =>  { 
464-             expect ( error ) . toMatch ( / k e y ,   g o t   l e n g t h = 6 4 / ) ; 
465-           } ) ; 
419+         await  expectAsync ( Xchacha20poly1305Ietf . encrypt ( message ,  key ,  nonce ) ) . toBeRejectedWithError ( 
420+           / k e y ,   g o t   l e n g t h = 6 4 / , 
421+         ) ; 
466422      } 
467423    } ) ; 
468424
@@ -482,38 +438,23 @@ describe("Libsodium", () => {
482438      { 
483439        // corrupted ciphertext 
484440        const  corruptedCiphertext  =  ciphertext . map ( ( x ,  i )  =>  ( i  ===  0  ? x  ^  0x01  : x ) ) ; 
485-         await  Xchacha20poly1305Ietf . decrypt ( corruptedCiphertext ,  key ,  nonce ) . then ( 
486-           ( )  =>  { 
487-             throw  new  Error ( "promise must not resolve" ) ; 
488-           } , 
489-           ( error )  =>  { 
490-             expect ( error . message ) . toMatch ( / i n v a l i d   t a g / i) ; 
491-           } , 
492-         ) ; 
441+         await  expectAsync ( 
442+           Xchacha20poly1305Ietf . decrypt ( corruptedCiphertext ,  key ,  nonce ) , 
443+         ) . toBeRejectedWithError ( / i n v a l i d   t a g / i) ; 
493444      } 
494445      { 
495446        // corrupted key 
496447        const  corruptedKey  =  key . map ( ( x ,  i )  =>  ( i  ===  0  ? x  ^  0x01  : x ) ) ; 
497-         await  Xchacha20poly1305Ietf . decrypt ( ciphertext ,  corruptedKey ,  nonce ) . then ( 
498-           ( )  =>  { 
499-             throw  new  Error ( "promise must not resolve" ) ; 
500-           } , 
501-           ( error )  =>  { 
502-             expect ( error . message ) . toMatch ( / i n v a l i d   t a g / i) ; 
503-           } , 
504-         ) ; 
448+         await  expectAsync ( 
449+           Xchacha20poly1305Ietf . decrypt ( ciphertext ,  corruptedKey ,  nonce ) , 
450+         ) . toBeRejectedWithError ( / i n v a l i d   t a g / i) ; 
505451      } 
506452      { 
507453        // corrupted nonce 
508454        const  corruptedNonce  =  nonce . map ( ( x ,  i )  =>  ( i  ===  0  ? x  ^  0x01  : x ) ) ; 
509-         await  Xchacha20poly1305Ietf . decrypt ( ciphertext ,  key ,  corruptedNonce ) . then ( 
510-           ( )  =>  { 
511-             throw  new  Error ( "promise must not resolve" ) ; 
512-           } , 
513-           ( error )  =>  { 
514-             expect ( error . message ) . toMatch ( / i n v a l i d   t a g / i) ; 
515-           } , 
516-         ) ; 
455+         await  expectAsync ( 
456+           Xchacha20poly1305Ietf . decrypt ( ciphertext ,  key ,  corruptedNonce ) , 
457+         ) . toBeRejectedWithError ( / i n v a l i d   t a g / i) ; 
517458      } 
518459    } ) ; 
519460
0 commit comments