-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
digest_hmac_sha1_base64.go
49 lines (40 loc) · 1.5 KB
/
digest_hmac_sha1_base64.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
// Code generated by __generator__/interpreter.go at once
package builtin
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"github.com/ysugimoto/falco/interpreter/context"
"github.com/ysugimoto/falco/interpreter/function/errors"
"github.com/ysugimoto/falco/interpreter/value"
)
const Digest_hmac_sha1_base64_Name = "digest.hmac_sha1_base64"
var Digest_hmac_sha1_base64_ArgumentTypes = []value.Type{value.StringType, value.StringType}
func Digest_hmac_sha1_base64_Validate(args []value.Value) error {
if len(args) != 2 {
return errors.ArgumentNotEnough(Digest_hmac_sha1_base64_Name, 2, args)
}
for i := range args {
if args[i].Type() != Digest_hmac_sha1_base64_ArgumentTypes[i] {
return errors.TypeMismatch(Digest_hmac_sha1_base64_Name, i+1, Digest_hmac_sha1_base64_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of digest.hmac_sha1_base64
// Arguments may be:
// - STRING, STRING
// Reference: https://developer.fastly.com/reference/vcl/functions/cryptographic/digest-hmac-sha1-base64/
func Digest_hmac_sha1_base64(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Digest_hmac_sha1_base64_Validate(args); err != nil {
return value.Null, err
}
key := value.Unwrap[*value.String](args[0])
input := value.Unwrap[*value.String](args[1])
mac := hmac.New(sha1.New, []byte(key.Value))
mac.Write([]byte(input.Value))
return &value.String{
Value: base64.StdEncoding.EncodeToString(mac.Sum(nil)),
}, nil
}