diff options
author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/minio/minio-go/v7/pkg/signer/utils.go | |
parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/minio/minio-go/v7/pkg/signer/utils.go')
-rw-r--r-- | vendor/github.com/minio/minio-go/v7/pkg/signer/utils.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/minio/minio-go/v7/pkg/signer/utils.go b/vendor/github.com/minio/minio-go/v7/pkg/signer/utils.go new file mode 100644 index 0000000..87c9939 --- /dev/null +++ b/vendor/github.com/minio/minio-go/v7/pkg/signer/utils.go | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * MinIO Go Library for Amazon S3 Compatible Cloud Storage | ||
3 | * Copyright 2015-2017 MinIO, Inc. | ||
4 | * | ||
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | * you may not use this file except in compliance with the License. | ||
7 | * You may obtain a copy of the License at | ||
8 | * | ||
9 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | * | ||
11 | * Unless required by applicable law or agreed to in writing, software | ||
12 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | * See the License for the specific language governing permissions and | ||
15 | * limitations under the License. | ||
16 | */ | ||
17 | |||
18 | package signer | ||
19 | |||
20 | import ( | ||
21 | "crypto/hmac" | ||
22 | "crypto/sha256" | ||
23 | "net/http" | ||
24 | "strings" | ||
25 | ) | ||
26 | |||
27 | // unsignedPayload - value to be set to X-Amz-Content-Sha256 header when | ||
28 | const unsignedPayload = "UNSIGNED-PAYLOAD" | ||
29 | |||
30 | // sum256 calculate sha256 sum for an input byte array. | ||
31 | func sum256(data []byte) []byte { | ||
32 | hash := sha256.New() | ||
33 | hash.Write(data) | ||
34 | return hash.Sum(nil) | ||
35 | } | ||
36 | |||
37 | // sumHMAC calculate hmac between two input byte array. | ||
38 | func sumHMAC(key, data []byte) []byte { | ||
39 | hash := hmac.New(sha256.New, key) | ||
40 | hash.Write(data) | ||
41 | return hash.Sum(nil) | ||
42 | } | ||
43 | |||
44 | // getHostAddr returns host header if available, otherwise returns host from URL | ||
45 | func getHostAddr(req *http.Request) string { | ||
46 | host := req.Header.Get("host") | ||
47 | if host != "" && req.Host != host { | ||
48 | return host | ||
49 | } | ||
50 | if req.Host != "" { | ||
51 | return req.Host | ||
52 | } | ||
53 | return req.URL.Host | ||
54 | } | ||
55 | |||
56 | // Trim leading and trailing spaces and replace sequential spaces with one space, following Trimall() | ||
57 | // in http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html | ||
58 | func signV4TrimAll(input string) string { | ||
59 | // Compress adjacent spaces (a space is determined by | ||
60 | // unicode.IsSpace() internally here) to one space and return | ||
61 | return strings.Join(strings.Fields(input), " ") | ||
62 | } | ||