11const test = require ( 'ava' )
2- const { createPrivateKey, createPublicKey } = require ( 'crypto' )
2+ const { createPrivateKey, createPublicKey, generateKeyPairSync } = require ( 'crypto' )
33const { hasProperty, hasNoProperties, hasProperties } = require ( '../macros' )
44const fixtures = require ( '../fixtures' )
5+ const errors = require ( '../../lib/errors' )
56
67const ECKey = require ( '../../lib/jwk/key/ec' )
78
@@ -10,6 +11,18 @@ test(`EC key .algorithms invalid operation`, t => {
1011 t . throws ( ( ) => key . algorithms ( 'foo' ) , { instanceOf : TypeError , message : 'invalid key operation' } )
1112} )
1213
14+ test ( 'Unusable with unsupported curves' , t => {
15+ const kp = generateKeyPairSync ( 'ec' , { namedCurve : 'secp224k1' } )
16+ t . throws (
17+ ( ) => new ECKey ( kp . privateKey ) ,
18+ { instanceOf : errors . JOSENotSupported , code : 'ERR_JOSE_NOT_SUPPORTED' , message : 'unsupported EC key curve' }
19+ )
20+ t . throws (
21+ ( ) => new ECKey ( kp . publicKey ) ,
22+ { instanceOf : errors . JOSENotSupported , code : 'ERR_JOSE_NOT_SUPPORTED' , message : 'unsupported EC key curve' }
23+ )
24+ } )
25+
1326Object . entries ( {
1427 'P-256' : [ 256 , 'rDd6H6t9-nJUoz72nTpz8tInvypVWhE2iQoPznj8ZY8' ] ,
1528 'P-256K' : [ 256 , 'zZYrH69YCAAihM7ZCoRj90VI55H5MmQscSpf-JuUS50' ] ,
0 commit comments