...
1 package jws
2
3 import (
4 "net/http"
5
6 "github.com/lestrrat-go/backoff/v2"
7 "github.com/lestrrat-go/jwx/jwk"
8 "github.com/lestrrat-go/option"
9 )
10
11 type Option = option.Interface
12
13 type identPayloadSigner struct{}
14 type identDetachedPayload struct{}
15 type identHeaders struct{}
16 type identMessage struct{}
17 type identFetchBackoff struct{}
18 type identFetchWhitelist struct{}
19 type identHTTPClient struct{}
20 type identJWKSetFetcher struct{}
21
22 func WithSigner(signer Signer, key interface{}, public, protected Headers) Option {
23 return option.New(identPayloadSigner{}, &payloadSigner{
24 signer: signer,
25 key: key,
26 protected: protected,
27 public: public,
28 })
29 }
30
31 type SignOption interface {
32 Option
33 signOption()
34 }
35
36 type signOption struct {
37 Option
38 }
39
40 func (*signOption) signOption() {}
41
42
43
44 func WithHeaders(h Headers) SignOption {
45 return &signOption{option.New(identHeaders{}, h)}
46 }
47
48
49 type VerifyOption interface {
50 Option
51 verifyOption()
52 }
53
54 type verifyOption struct {
55 Option
56 }
57
58 func (*verifyOption) verifyOption() {}
59
60
61
62 func WithMessage(m *Message) VerifyOption {
63 return &verifyOption{option.New(identMessage{}, m)}
64 }
65
66 type SignVerifyOption interface {
67 SignOption
68 VerifyOption
69 }
70
71 type signVerifyOption struct {
72 Option
73 }
74
75 func (*signVerifyOption) signOption() {}
76 func (*signVerifyOption) verifyOption() {}
77
78
79
80
81
82
83
84
85 func WithDetachedPayload(v []byte) SignVerifyOption {
86 return &signVerifyOption{option.New(identDetachedPayload{}, v)}
87 }
88
89
90
91
92
93
94 func WithFetchWhitelist(wl jwk.Whitelist) VerifyOption {
95 return &verifyOption{option.New(identFetchWhitelist{}, wl)}
96 }
97
98
99
100
101
102 func WithFetchBackoff(b backoff.Policy) VerifyOption {
103 return &verifyOption{option.New(identFetchBackoff{}, b)}
104 }
105
106
107
108
109
110 func WithHTTPClient(httpcl *http.Client) VerifyOption {
111 return &verifyOption{option.New(identHTTPClient{}, httpcl)}
112 }
113
114
115
116
117 func WithJWKSetFetcher(f JWKSetFetcher) VerifyOption {
118 return &verifyOption{option.New(identJWKSetFetcher{}, f)}
119 }
120
View as plain text