-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathalgs.go
49 lines (43 loc) · 1.32 KB
/
algs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package jwt
import "fmt"
// Alg represents asymmetric signing algorithms
type Alg string
const (
// JOSE asymmetric signing algorithm values as defined by RFC 7518.
//
// See: https://tools.ietf.org/html/rfc7518#section-3.1
RS256 Alg = "RS256" // RSASSA-PKCS-v1.5 using SHA-256
RS384 Alg = "RS384" // RSASSA-PKCS-v1.5 using SHA-384
RS512 Alg = "RS512" // RSASSA-PKCS-v1.5 using SHA-512
ES256 Alg = "ES256" // ECDSA using P-256 and SHA-256
ES384 Alg = "ES384" // ECDSA using P-384 and SHA-384
ES512 Alg = "ES512" // ECDSA using P-521 and SHA-512
PS256 Alg = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
PS384 Alg = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
PS512 Alg = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
EdDSA Alg = "EdDSA" // Ed25519 using SHA-512
)
var supportedAlgorithms = map[Alg]bool{
RS256: true,
RS384: true,
RS512: true,
ES256: true,
ES384: true,
ES512: true,
PS256: true,
PS384: true,
PS512: true,
EdDSA: true,
}
// SupportedSigningAlgorithm returns an error if any of the given Algs
// are not supported signing algorithms.
func SupportedSigningAlgorithm(algs ...Alg) error {
for _, a := range algs {
if !supportedAlgorithms[a] {
return fmt.Errorf("unsupported signing algorithm %q", a)
}
}
return nil
}