@@ -708,4 +708,142 @@ routes.set("/crypto.subtle", async () => {
708
708
return pass ( ) ;
709
709
} ) ;
710
710
}
711
+ }
712
+
713
+ // verify
714
+ {
715
+ routes . set ( "/crypto.subtle.verify" , async ( ) => {
716
+ error = assert ( typeof crypto . subtle . verify , 'function' , `typeof crypto.subtle.verify` )
717
+ if ( error ) { return error ; }
718
+ error = assert ( crypto . subtle . verify , SubtleCrypto . prototype . verify , `crypto.subtle.verify === SubtleCrypto.prototype.verify` )
719
+ if ( error ) { return error ; }
720
+ return pass ( ) ;
721
+ } ) ;
722
+ routes . set ( "/crypto.subtle.verify/length" , async ( ) => {
723
+ error = assert ( crypto . subtle . verify . length , 4 , `crypto.subtle.verify.length === 4` )
724
+ if ( error ) { return error ; }
725
+ return pass ( ) ;
726
+ } ) ;
727
+ routes . set ( "/crypto.subtle.verify/called-as-constructor" , async ( ) => {
728
+ error = assertThrows ( ( ) => {
729
+ new crypto . subtle . verify
730
+ } , TypeError , "crypto.subtle.verify is not a constructor" )
731
+ if ( error ) { return error ; }
732
+ return pass ( ) ;
733
+ } ) ;
734
+ routes . set ( "/crypto.subtle.verify/called-with-wrong-this" , async ( ) => {
735
+ error = await assertRejects ( async ( ) => {
736
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
737
+ await crypto . subtle . verify . call ( undefined , jsonWebKeyAlgorithm , key , new Uint8Array , new Uint8Array )
738
+ } , TypeError , "Method SubtleCrypto.verify called on receiver that's not an instance of SubtleCrypto" )
739
+ if ( error ) { return error ; }
740
+ return pass ( ) ;
741
+ } ) ;
742
+ routes . set ( "/crypto.subtle.verify/called-with-no-arguments" , async ( ) => {
743
+ error = await assertRejects ( async ( ) => {
744
+ await crypto . subtle . verify ( )
745
+ } , TypeError , "SubtleCrypto.verify: At least 4 arguments required, but only 0 passed" )
746
+ if ( error ) { return error ; }
747
+ return pass ( ) ;
748
+ } ) ;
749
+ // first-parameter
750
+ {
751
+ routes . set ( "/crypto.subtle.verify/first-parameter-calls-7.1.17-ToString" , async ( ) => {
752
+ const sentinel = Symbol ( "sentinel" ) ;
753
+ const test = async ( ) => {
754
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
755
+ await crypto . subtle . verify ( {
756
+ name : {
757
+ toString ( ) {
758
+ throw sentinel ;
759
+ }
760
+ }
761
+ } , key , new Uint8Array , new Uint8Array ) ;
762
+ }
763
+ let error = await assertRejects ( test )
764
+ if ( error ) { return error ; }
765
+ try {
766
+ await test ( )
767
+ } catch ( thrownError ) {
768
+ let error = assert ( thrownError , sentinel , 'thrownError === sentinel' )
769
+ if ( error ) { return error ; }
770
+ }
771
+ return pass ( ) ;
772
+ } ) ;
773
+ routes . set ( "/crypto.subtle.verify/first-parameter-non-existant-algorithm" , async ( ) => {
774
+ let error = await assertRejects ( async ( ) => {
775
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
776
+ await crypto . subtle . verify ( 'jake' , key , new Uint8Array , new Uint8Array )
777
+ } , Error , "Algorithm: Unrecognized name" )
778
+ if ( error ) { return error ; }
779
+ return pass ( ) ;
780
+ } ) ;
781
+ }
782
+ // second-parameter
783
+ {
784
+ routes . set ( "/crypto.subtle.verify/second-parameter-invalid-format" , async ( ) => {
785
+ let error = await assertRejects ( async ( ) => {
786
+ await crypto . subtle . verify ( jsonWebKeyAlgorithm , "jake" , new Uint8Array , new Uint8Array )
787
+ } , Error , "parameter 2 is not of type 'CryptoKey'" )
788
+ if ( error ) { return error ; }
789
+ return pass ( ) ;
790
+ } ) ;
791
+ routes . set ( "/crypto.subtle.verify/second-parameter-invalid-usages" , async ( ) => {
792
+ let error = await assertRejects ( async ( ) => {
793
+ const key = await crypto . subtle . importKey ( 'jwk' , privateJsonWebKeyData , jsonWebKeyAlgorithm , privateJsonWebKeyData . ext , privateJsonWebKeyData . key_ops ) ;
794
+ await crypto . subtle . verify ( jsonWebKeyAlgorithm , key , new Uint8Array ( ) , new Uint8Array ( ) ) ;
795
+ } , Error , "CryptoKey doesn't support verification" )
796
+ if ( error ) { return error ; }
797
+ return pass ( ) ;
798
+ } ) ;
799
+ }
800
+ // third-parameter
801
+ {
802
+ routes . set ( "/crypto.subtle.verify/third-parameter-invalid-format" , async ( ) => {
803
+ let error = await assertRejects ( async ( ) => {
804
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
805
+ await crypto . subtle . verify ( jsonWebKeyAlgorithm , key , undefined , new Uint8Array ( ) ) ;
806
+ } , Error , "SubtleCrypto.verify: signature (argument 3) must be of type ArrayBuffer or ArrayBufferView but got \"\"" )
807
+ if ( error ) { return error ; }
808
+ return pass ( ) ;
809
+ } ) ;
810
+ }
811
+ // fourth-parameter
812
+ {
813
+ routes . set ( "/crypto.subtle.verify/fourth-parameter-invalid-format" , async ( ) => {
814
+ let error = await assertRejects ( async ( ) => {
815
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
816
+ await crypto . subtle . verify ( jsonWebKeyAlgorithm , key , new Uint8Array ( ) , undefined ) ;
817
+ } , Error , "SubtleCrypto.verify: data (argument 4) must be of type ArrayBuffer or ArrayBufferView but got \"\"" )
818
+ if ( error ) { return error ; }
819
+ return pass ( ) ;
820
+ } ) ;
821
+ }
822
+ // incorrect-signature
823
+ {
824
+ routes . set ( "/crypto.subtle.verify/incorrect-signature" , async ( ) => {
825
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
826
+ const signature = new Uint8Array ;
827
+ const enc = new TextEncoder ( ) ;
828
+ const data = enc . encode ( 'hello world' ) ;
829
+ const result = await crypto . subtle . verify ( jsonWebKeyAlgorithm , key , signature , data ) ;
830
+ error = assert ( result , false , "result === false" ) ;
831
+ if ( error ) { return error ; }
832
+ return pass ( ) ;
833
+ } ) ;
834
+ }
835
+ // correct-signature
836
+ {
837
+ routes . set ( "/crypto.subtle.verify/incorrect-signature" , async ( ) => {
838
+ const pkey = await crypto . subtle . importKey ( 'jwk' , privateJsonWebKeyData , jsonWebKeyAlgorithm , privateJsonWebKeyData . ext , privateJsonWebKeyData . key_ops ) ;
839
+ const key = await crypto . subtle . importKey ( 'jwk' , publicJsonWebKeyData , jsonWebKeyAlgorithm , publicJsonWebKeyData . ext , publicJsonWebKeyData . key_ops ) ;
840
+ const enc = new TextEncoder ( ) ;
841
+ const data = enc . encode ( 'hello world' ) ;
842
+ const signature = await crypto . subtle . sign ( jsonWebKeyAlgorithm , pkey , data ) ;
843
+ const result = await crypto . subtle . verify ( jsonWebKeyAlgorithm , key , signature , data ) ;
844
+ error = assert ( result , true , "result === true" ) ;
845
+ if ( error ) { return error ; }
846
+ return pass ( ) ;
847
+ } ) ;
848
+ }
711
849
}
0 commit comments