forked from lestrrat-go/jwx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elliptic_gen.go
84 lines (73 loc) · 2.4 KB
/
elliptic_gen.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// this file was auto-generated by internal/cmd/gentypes/main.go: DO NOT EDIT
package jwa
import (
"fmt"
"sort"
"sync"
"github.com/pkg/errors"
)
// EllipticCurveAlgorithm represents the algorithms used for EC keys
type EllipticCurveAlgorithm string
// Supported values for EllipticCurveAlgorithm
const (
Ed25519 EllipticCurveAlgorithm = "Ed25519"
Ed448 EllipticCurveAlgorithm = "Ed448"
InvalidEllipticCurve EllipticCurveAlgorithm = "P-invalid"
P256 EllipticCurveAlgorithm = "P-256"
P384 EllipticCurveAlgorithm = "P-384"
P521 EllipticCurveAlgorithm = "P-521"
X25519 EllipticCurveAlgorithm = "X25519"
X448 EllipticCurveAlgorithm = "X448"
)
var allEllipticCurveAlgorithms = map[EllipticCurveAlgorithm]struct{}{
Ed25519: {},
Ed448: {},
P256: {},
P384: {},
P521: {},
X25519: {},
X448: {},
}
var listEllipticCurveAlgorithmOnce sync.Once
var listEllipticCurveAlgorithm []EllipticCurveAlgorithm
// EllipticCurveAlgorithms returns a list of all available values for EllipticCurveAlgorithm
func EllipticCurveAlgorithms() []EllipticCurveAlgorithm {
listEllipticCurveAlgorithmOnce.Do(func() {
listEllipticCurveAlgorithm = make([]EllipticCurveAlgorithm, 0, len(allEllipticCurveAlgorithms))
for v := range allEllipticCurveAlgorithms {
listEllipticCurveAlgorithm = append(listEllipticCurveAlgorithm, v)
}
sort.Slice(listEllipticCurveAlgorithm, func(i, j int) bool {
return string(listEllipticCurveAlgorithm[i]) < string(listEllipticCurveAlgorithm[j])
})
})
return listEllipticCurveAlgorithm
}
// Accept is used when conversion from values given by
// outside sources (such as JSON payloads) is required
func (v *EllipticCurveAlgorithm) Accept(value interface{}) error {
var tmp EllipticCurveAlgorithm
if x, ok := value.(EllipticCurveAlgorithm); ok {
tmp = x
} else {
var s string
switch x := value.(type) {
case fmt.Stringer:
s = x.String()
case string:
s = x
default:
return errors.Errorf(`invalid type for jwa.EllipticCurveAlgorithm: %T`, value)
}
tmp = EllipticCurveAlgorithm(s)
}
if _, ok := allEllipticCurveAlgorithms[tmp]; !ok {
return errors.Errorf(`invalid jwa.EllipticCurveAlgorithm value`)
}
*v = tmp
return nil
}
// String returns the string representation of a EllipticCurveAlgorithm
func (v EllipticCurveAlgorithm) String() string {
return string(v)
}