-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathidentity.go
40 lines (37 loc) · 1.07 KB
/
identity.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
package smartid
import (
"crypto/x509/pkix"
"strings"
)
// Identity represents simpler format of PKIX Subject.
type Identity struct {
Country string
Organization string
OrganizationalUnit string
Locality string
Province string
StreetAddress string
PostalCode string
SerialNumber string
CommonName string
}
// newIdentity makes identity from PKIX Subject retrieved
// from certificate.
//
// This is very primitive PKIX Subject parsing, but should be enough
// for Smart-ID.
//
// TODO: refactor
func newIdentity(n *pkix.Name) *Identity {
return &Identity{
Country: strings.Join(n.Country, ""),
Organization: strings.Join(n.Organization, ""),
OrganizationalUnit: strings.Join(n.OrganizationalUnit, ""),
Locality: strings.Join(n.Locality, ""),
Province: strings.Join(n.Province, ""),
StreetAddress: strings.Join(n.StreetAddress, ""),
PostalCode: strings.Join(n.PostalCode, ""),
SerialNumber: n.SerialNumber,
CommonName: n.CommonName,
}
}