-
Notifications
You must be signed in to change notification settings - Fork 6
/
subjects_common.go
45 lines (35 loc) · 1.03 KB
/
subjects_common.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
/*
* Copyright (c) 2020 Entrust Datacard Corporation.
* All rights reserved.
*/
package main
import (
"fmt"
"strings"
"gopkg.in/ldap.v2"
)
func processSubjectVariables(subjectVars string) ([]SubjectVariable, error) {
dn, err := ldap.ParseDN(subjectVars)
if err != nil {
return nil, fmt.Errorf("error parsing the subject variables: %s", err)
}
var subjectVariables []SubjectVariable
for _, v := range (*dn).RDNs {
var attributes []*ldap.AttributeTypeAndValue = v.Attributes
for _, a := range attributes {
subjectVariables = append(subjectVariables, SubjectVariable{a.Type, a.Value})
}
}
return subjectVariables, nil
}
func processSubjectAltNames(subjectAltNames []string) ([]SubjectAltName, error) {
var altNames []SubjectAltName
for _, tv := range subjectAltNames {
out := strings.SplitN(tv, "=", 2)
if len(out) != 2 {
return nil, fmt.Errorf("error parsing the subject alt names: %s", subjectAltNames)
}
altNames = append(altNames, SubjectAltName{Type: out[0], Value: out[1]})
}
return altNames, nil
}