@@ -1031,3 +1031,66 @@ if (hasOpenSSL(3, 2)) {
10311031 assert . strictEqual ( crypto . verify ( 'SHA256' , dataBuffer , publicKey , sigSAB ) , true ) ;
10321032 }
10331033}
1034+
1035+ // Test that sign/verify error messages use correct property paths
1036+ {
1037+ // Sign with invalid format
1038+ assert . throws ( ( ) => {
1039+ crypto . createSign ( 'SHA256' ) . update ( 'test' ) . sign ( {
1040+ key : Buffer . alloc ( 0 ) , format : 'banana' , type : 'pkcs8' ,
1041+ } ) ;
1042+ } , {
1043+ code : 'ERR_INVALID_ARG_VALUE' ,
1044+ message : / p r i v a t e K e y \. f o r m a t / ,
1045+ } ) ;
1046+
1047+ // Sign with invalid type
1048+ assert . throws ( ( ) => {
1049+ crypto . createSign ( 'SHA256' ) . update ( 'test' ) . sign ( {
1050+ key : Buffer . alloc ( 0 ) , format : 'der' , type : 'banana' ,
1051+ } ) ;
1052+ } , {
1053+ code : 'ERR_INVALID_ARG_VALUE' ,
1054+ message : / p r i v a t e K e y \. t y p e / ,
1055+ } ) ;
1056+
1057+ // Verify with invalid format
1058+ assert . throws ( ( ) => {
1059+ crypto . createVerify ( 'SHA256' ) . update ( 'test' ) . verify ( {
1060+ key : Buffer . alloc ( 0 ) , format : 'banana' , type : 'spki' ,
1061+ } , Buffer . alloc ( 0 ) ) ;
1062+ } , {
1063+ code : 'ERR_INVALID_ARG_VALUE' ,
1064+ message : / k e y \. f o r m a t / ,
1065+ } ) ;
1066+
1067+ // Verify with invalid type
1068+ assert . throws ( ( ) => {
1069+ crypto . createVerify ( 'SHA256' ) . update ( 'test' ) . verify ( {
1070+ key : Buffer . alloc ( 0 ) , format : 'der' , type : 'banana' ,
1071+ } , Buffer . alloc ( 0 ) ) ;
1072+ } , {
1073+ code : 'ERR_INVALID_ARG_VALUE' ,
1074+ message : / k e y \. t y p e / ,
1075+ } ) ;
1076+
1077+ // crypto.sign with invalid format
1078+ assert . throws ( ( ) => {
1079+ crypto . sign ( 'SHA256' , Buffer . from ( 'test' ) , {
1080+ key : Buffer . alloc ( 0 ) , format : 'banana' , type : 'pkcs8' ,
1081+ } ) ;
1082+ } , {
1083+ code : 'ERR_INVALID_ARG_VALUE' ,
1084+ message : / k e y \. f o r m a t / ,
1085+ } ) ;
1086+
1087+ // crypto.verify with invalid format
1088+ assert . throws ( ( ) => {
1089+ crypto . verify ( 'SHA256' , Buffer . from ( 'test' ) , {
1090+ key : Buffer . alloc ( 0 ) , format : 'banana' , type : 'spki' ,
1091+ } , Buffer . alloc ( 0 ) ) ;
1092+ } , {
1093+ code : 'ERR_INVALID_ARG_VALUE' ,
1094+ message : / k e y \. f o r m a t / ,
1095+ } ) ;
1096+ }
0 commit comments