cloudflare/cfssl_trust

Public

mirrored from https://github.com/cloudflare/cfssl_trustAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f95cb288cfce97fcc2538a97adcd00a2e95c1fca

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

common/subject.go

45lines · modecode

1package common
2
3import (
4 "crypto/x509/pkix"
5 "fmt"
6 "strings"
7)
8
9// DateFormat defines the format for printing time.Time values
10const DateFormat = "2006-01-02T15:04:05-0700"
11
12// NameToString stringifies a X.509 distinguished name.
13func NameToString(name pkix.Name) string {
14 var ns []string
15
16 if name.CommonName != "" {
17 ns = append(ns, name.CommonName)
18 }
19
20 for i := range name.Country {
21 ns = append(ns, fmt.Sprintf("C=%s", name.Country[i]))
22 }
23
24 for i := range name.Organization {
25 ns = append(ns, fmt.Sprintf("O=%s", name.Organization[i]))
26 }
27
28 for i := range name.OrganizationalUnit {
29 ns = append(ns, fmt.Sprintf("OU=%s", name.OrganizationalUnit[i]))
30 }
31
32 for i := range name.Locality {
33 ns = append(ns, fmt.Sprintf("L=%s", name.Locality[i]))
34 }
35
36 for i := range name.Province {
37 ns = append(ns, fmt.Sprintf("ST=%s", name.Province[i]))
38 }
39
40 if len(ns) > 0 {
41 return "/" + strings.Join(ns, "/")
42 }
43
44 return "*** no subject information ***"
45}
46