Skip to content

Commit 2c14a6e

Browse files
committed
Add more doc strings
1 parent 49edc54 commit 2c14a6e

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

httpsig.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ func sliceHas(haystack []string, needle string) bool {
2525
}
2626

2727
// NewSignTransport returns a new client transport that wraps the provided transport with
28-
// http message signing and body digest creation
28+
// http message signing and body digest creation.
29+
//
30+
// Use the various `WithSign*` option funcs to configure signature algorithms with their provided
31+
// key ids. You must provide at least one signing option. A signature for every provided key id is
32+
// included on each request. Multiple included signatures allow you to gracefully introduce stronger
33+
// algorithms, rotate keys, etc.
2934
func NewSignTransport(transport http.RoundTripper, opts ...signOption) http.RoundTripper {
3035
s := signer{}
3136

@@ -90,9 +95,15 @@ func (r rt) RoundTrip(req *http.Request) (*http.Response, error) { return r(req)
9095
// NewVerifyMiddleware returns a configured http server middleware that can be used to wrap
9196
// multiple handlers for http message signature and digest verification.
9297
//
93-
// TODO: form and multipart support
98+
// Use the `WithVerify*` option funcs to configure signature verification algorithms that map
99+
// to their provided key ids.
100+
//
101+
// Requests with missing signatures, malformed signature headers, expired signatures, or
102+
// invalid signatures are rejected with a `400` response. Only one valid signature is required
103+
// from the known key ids. However, only the first known key id is checked.
94104
func NewVerifyMiddleware(opts ...verifyOption) func(http.Handler) http.Handler {
95105

106+
// TODO: form and multipart support
96107
v := verifier{}
97108

98109
for _, o := range opts {
@@ -168,35 +179,51 @@ type optImpl struct {
168179
func (o *optImpl) configureSign(s *signer) { o.s(s) }
169180
func (o *optImpl) configureVerify(v *verifier) { o.v(v) }
170181

171-
// TODO: use this to implement required headers in verify?
182+
// WithHeaders sets the list of headers that will be included in the signature.
183+
// The Digest header is always included (and the digest calculated).
184+
//
185+
// If not provided, the default headers `content-type, content-length, host` are used.
172186
func WithHeaders(hdr ...string) signOption {
187+
// TODO: use this to implement required headers in verify?
173188
return &optImpl{
174189
s: func(s *signer) { s.headers = hdr },
175190
}
176191
}
177192

193+
// WithSignRsaPssSha512 adds signing using `rsa-pss-sha512` with the given private key
194+
// using the given key id.
178195
func WithSignRsaPssSha512(keyID string, pk *rsa.PrivateKey) signOption {
179196
return &optImpl{
180197
s: func(s *signer) { s.keys[keyID] = signRsaPssSha512(pk) },
181198
}
182199
}
200+
201+
// WithVerifyRsaPssSha512 adds signature verification using `rsa-pss-sha512` with the
202+
// given public key using the given key id.
183203
func WithVerifyRsaPssSha512(keyID string, pk *rsa.PublicKey) verifyOption {
184204
return &optImpl{
185205
v: func(v *verifier) { v.keys[keyID] = verifyRsaPssSha512(pk) },
186206
}
187207
}
188208

209+
// WithSignEcdsaP256Sha256 adds signing using `ecdsa-p256-sha256` with the given private key
210+
// using the given key id.
189211
func WithSignEcdsaP256Sha256(keyID string, pk *ecdsa.PrivateKey) signOption {
190212
return &optImpl{
191213
s: func(s *signer) { s.keys[keyID] = signEccP256(pk) },
192214
}
193215
}
216+
217+
// WithVerifyEcdsaP256Sha256 adds signature verification using `ecdsa-p256-sha256` with the
218+
// given public key using the given key id.
194219
func WithVerifyEcdsaP256Sha256(keyID string, pk *ecdsa.PublicKey) verifyOption {
195220
return &optImpl{
196221
v: func(v *verifier) { v.keys[keyID] = verifyEccP256(pk) },
197222
}
198223
}
199224

225+
// WithHmacSha256 adds signing or signature verification using `hmac-sha256` with the
226+
// given shared secret using the given key id.
200227
func WithHmacSha256(keyID string, secret []byte) signOrVerifyOption {
201228
return &optImpl{
202229
s: func(s *signer) { s.keys[keyID] = signHmacSha256(secret) },

0 commit comments

Comments
 (0)