Skip to content

Commit 602f3a3

Browse files
committed
allow ES384 and 512
1 parent f9f2c5a commit 602f3a3

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

src/algorithms/index.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,23 @@ supportedAlgorithms.define('ES256', 'sign', new ECDSA({
6464
},
6565
namedCurve: 'P-256'
6666
}))
67-
//supportedAlgorithms.define('ES384', 'sign', {})
68-
//supportedAlgorithms.define('ES512', 'sign', {})
67+
68+
supportedAlgorithms.define('ES384', 'sign', new ECDSA({
69+
name: 'ECDSA',
70+
hash: {
71+
name: 'SHA-384'
72+
},
73+
namedCurve: 'P-384'
74+
}))
75+
76+
supportedAlgorithms.define('ES512', 'sign', new ECDSA({
77+
name: 'ECDSA',
78+
hash: {
79+
name: 'SHA-512'
80+
},
81+
namedCurve: 'P-521'
82+
}))
83+
6984
//supportedAlgorithms.define('PS256', 'sign', {})
7085
//supportedAlgorithms.define('PS384', 'sign', {})
7186
//supportedAlgorithms.define('PS512', 'sign', {})
@@ -126,8 +141,23 @@ supportedAlgorithms.define('ES256', 'verify', new ECDSA({
126141
},
127142
namedCurve: 'P-256'
128143
}))
129-
//supportedAlgorithms.define('ES384', 'verify', {})
130-
//supportedAlgorithms.define('ES512', 'verify', {})
144+
145+
supportedAlgorithms.define('ES384', 'verify', new ECDSA({
146+
name: 'ECDSA',
147+
hash: {
148+
name: 'SHA-384'
149+
},
150+
namedCurve: 'P-384'
151+
}))
152+
153+
supportedAlgorithms.define('ES512', 'verify', new ECDSA({
154+
name: 'ECDSA',
155+
hash: {
156+
name: 'SHA-512'
157+
},
158+
namedCurve: 'P-521'
159+
}))
160+
131161
//supportedAlgorithms.define('PS256', 'verify', {})
132162
//supportedAlgorithms.define('PS384', 'verify', {})
133163
//supportedAlgorithms.define('PS512', 'verify', {})
@@ -165,6 +195,22 @@ supportedAlgorithms.define('ES256', 'importKey', new ECDSA({
165195
namedCurve: 'P-256'
166196
}))
167197

198+
supportedAlgorithms.define('ES384', 'importKey', new ECDSA({
199+
name: 'ECDSA',
200+
hash: {
201+
name: 'SHA-384'
202+
},
203+
namedCurve: 'P-384'
204+
}))
205+
206+
supportedAlgorithms.define('ES512', 'importKey', new ECDSA({
207+
name: 'ECDSA',
208+
hash: {
209+
name: 'SHA-512'
210+
},
211+
namedCurve: 'P-521'
212+
}))
213+
168214
/**
169215
* Export
170216
*/

src/jose/JWA.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class JWA {
8787
*/
8888
static async importKey (key) {
8989
let normalizedAlgorithm = supportedAlgorithms.normalize('importKey', key.alg)
90+
91+
if (normalizedAlgorithm instanceof Error) {
92+
return Promise.reject(new NotSupportedError(key.alg))
93+
}
94+
9095
return normalizedAlgorithm.importKey(key)
9196
}
9297
}

0 commit comments

Comments
 (0)