-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
75 lines (64 loc) · 1.36 KB
/
utils.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
/*
* Copyright (c) 2023 Zander Schwid & Co. LLC.
* SPDX-License-Identifier: BUSL-1.1
*/
package certmod
import (
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/challenge/dns01"
"strings"
)
func indexStrings(a []string) map[string]bool {
m := make(map[string]bool)
for _, part := range a {
key := strings.TrimSpace(part)
m[key] = true
}
return m
}
func asList(m map[string]bool) []string {
var a []string
for k := range m {
a = append(a, k)
}
return a
}
func getKeyType(algorithm string) certcrypto.KeyType {
switch strings.ToUpper(algorithm) {
case "RSA2048":
return certcrypto.RSA2048
case "RSA4096":
return certcrypto.RSA4096
case "RSA8192":
return certcrypto.RSA8192
case "EC256":
return certcrypto.EC256
case "EC384":
return certcrypto.EC384
}
return certcrypto.RSA2048
}
func ToZone(domain string) (string, error) {
fqdn := ToFqdn(domain)
zone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return "", err
}
return UnFqdn(zone), nil
}
// ToFqdn converts the name into a fqdn appending a trailing dot.
func ToFqdn(name string) string {
n := len(name)
if n == 0 || name[n-1] == '.' {
return name
}
return name + "."
}
// UnFqdn converts the fqdn into a name removing the trailing dot.
func UnFqdn(name string) string {
n := len(name)
if n != 0 && name[n-1] == '.' {
return name[:n-1]
}
return name
}