@@ -468,11 +468,7 @@ async function importRsaPkcs8() {
468468 pemHeader . length ,
469469 keyFile . length - pemFooter . length ,
470470 ) ;
471- const binaryDerString = atob ( pemContents ) ;
472- const binaryDer = new Uint8Array ( binaryDerString . length ) ;
473- for ( let i = 0 ; i < binaryDerString . length ; i ++ ) {
474- binaryDer [ i ] = binaryDerString . charCodeAt ( i ) ;
475- }
471+ const binaryDer = Uint8Array . fromBase64 ( pemContents ) ;
476472
477473 const key = await crypto . subtle . importKey (
478474 "pkcs8" ,
@@ -514,11 +510,7 @@ async function importRsaSpki() {
514510 pemHeader . length ,
515511 keyFile . length - pemFooter . length ,
516512 ) ;
517- const binaryDerString = atob ( pemContents ) ;
518- const binaryDer = new Uint8Array ( binaryDerString . length ) ;
519- for ( let i = 0 ; i < binaryDerString . length ; i ++ ) {
520- binaryDer [ i ] = binaryDerString . charCodeAt ( i ) ;
521- }
513+ const binaryDer = Uint8Array . fromBase64 ( pemContents ) ;
522514
523515 const key = await crypto . subtle . importKey (
524516 "spki" ,
@@ -755,11 +747,7 @@ async function importNonInteroperableRsaPkcs8() {
755747 pemHeader . length ,
756748 keyFile . length - pemFooter . length ,
757749 ) ;
758- const binaryDerString = atob ( pemContents ) ;
759- const binaryDer = new Uint8Array ( binaryDerString . length ) ;
760- for ( let i = 0 ; i < binaryDerString . length ; i ++ ) {
761- binaryDer [ i ] = binaryDerString . charCodeAt ( i ) ;
762- }
750+ const binaryDer = Uint8Array . fromBase64 ( pemContents ) ;
763751
764752 await expect (
765753 crypto . subtle . importKey (
@@ -1745,9 +1733,7 @@ async function testHMACSign() {
17451733 cryptoKey ,
17461734 new Uint8Array ( 8 ) ,
17471735 ) ;
1748- const actualBase64String = btoa (
1749- String . fromCharCode ( ...new Uint8Array ( actual ) ) ,
1750- ) ;
1736+ const actualBase64String = new Uint8Array ( actual ) . toBase64 ( ) ;
17511737 // This value is from running the above code in a browser
17521738 const expected = "SdJ6jecfYHT1LzY/Vh03WauHRbzWZeVjDFL4ietJNCw=" ;
17531739 assert . strictEqual ( actualBase64String , expected ) ;
@@ -1771,12 +1757,7 @@ async function testHMACVerify() {
17711757 [ "verify" ] ,
17721758 ) ;
17731759
1774- // Convert the base64 signature back to Uint8Array
1775- const signature = new Uint8Array (
1776- atob ( base64Signature )
1777- . split ( "" )
1778- . map ( ( c ) => c . charCodeAt ( 0 ) ) ,
1779- ) ;
1760+ const signature = Uint8Array . fromBase64 ( base64Signature ) ;
17801761
17811762 const isVerified = await subtle . verify (
17821763 { name : "HMAC" } ,
@@ -1810,9 +1791,7 @@ async function testHMACSignAlternativeSyntax() {
18101791 await subtle . importKey ( "raw" , key . buffer , importParams , false , [ "sign" ] ) ;
18111792
18121793 const actual = await subtle . sign ( "hmac" , cryptoKey , new Uint8Array ( 8 ) ) ;
1813- const actualBase64String = btoa (
1814- String . fromCharCode ( ...new Uint8Array ( actual ) ) ,
1815- ) ;
1794+ const actualBase64String = new Uint8Array ( actual ) . toBase64 ( ) ;
18161795 // This value is from running the above code in a browser
18171796 const expected = "SdJ6jecfYHT1LzY/Vh03WauHRbzWZeVjDFL4ietJNCw=" ;
18181797 assert . strictEqual ( actualBase64String , expected ) ;
@@ -1914,7 +1893,7 @@ async function testDigest() {
19141893 "SHA-256" ,
19151894 new TextEncoder ( ) . encode ( "hello" ) ,
19161895 ) ;
1917- const digestBase64 = btoa ( String . fromCharCode ( ... new Uint8Array ( digest ) ) ) ;
1896+ const digestBase64 = new Uint8Array ( digest ) . toBase64 ( ) ;
19181897 assert . strictEqual (
19191898 digestBase64 ,
19201899 "LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=" ,
0 commit comments