diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-09-01 02:14:48 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-09-01 02:14:48 -0600 |
commit | 4dae5b626ff4b64dc719abc46150976c6ba329a9 (patch) | |
tree | 0c43b3952863ec6b609a5d4bb656455437d4f666 /bin-src | |
parent | cde2c6e7fb4ff62dfb6b3be3b48a1acdb30668a7 (diff) |
Diffstat (limited to 'bin-src')
-rw-r--r-- | bin-src/crtsh-pem2html.go | 24 | ||||
-rw-r--r-- | bin-src/pem-diff.go | 16 | ||||
-rw-r--r-- | bin-src/tls-pem2html.go | 24 |
3 files changed, 11 insertions, 53 deletions
diff --git a/bin-src/crtsh-pem2html.go b/bin-src/crtsh-pem2html.go index e246654..dd95b55 100644 --- a/bin-src/crtsh-pem2html.go +++ b/bin-src/crtsh-pem2html.go @@ -161,24 +161,6 @@ func (certs CertSet) Updated() time.Time { return ret } -type CertList []CertSet - -// Len is the number of elements in the collection. -func (l CertList) Len() int { - return len(l) -} - -// Less reports whether the element with -// index i should sort before the element with index j. -func (l CertList) Less(i, j int) bool { - return l[i].Updated().After(l[j].Updated()) -} - -// Swap swaps the elements with indexes i and j. -func (l CertList) Swap(i, j int) { - l[i], l[j] = l[j], l[i] -} - func main() { if err := mainWithError(); err != nil { _, _ = fmt.Fprintf(os.Stderr, "%s: error: %v", os.Args[0], err) @@ -223,12 +205,14 @@ func mainWithError() error { bySerial[serial] = append(bySerial[serial], cert) } - var certs CertList + var certs []CertSet for _, set := range bySerial { certs = append(certs, NewCertSet(set)...) } - sort.Sort(certs) + sort.Slice(certs, func(i, j int) bool { + return certs[i].Updated().After(certs[j].Updated()) + }) if err := tmpl.Execute(os.Stdout, map[string]any{"certs": certs, "now": now}); err != nil { return fmt.Errorf("could not execute template: %w", err) } diff --git a/bin-src/pem-diff.go b/bin-src/pem-diff.go index f4bacee..b1c1ac7 100644 --- a/bin-src/pem-diff.go +++ b/bin-src/pem-diff.go @@ -7,9 +7,10 @@ import ( "encoding/pem" "fmt" "io" + "maps" "net/url" "os" - "sort" + "slices" "strings" "git.lukeshu.com/dashboard/bin-src/util" @@ -102,17 +103,6 @@ func readCrtSh(filename string, hosts []string) (map[string]Cert, error) { return ret, nil } -func keys(m map[string]Cert) []string { - ret := make([]string, len(m)) - i := 0 - for k := range m { - ret[i] = k - i++ - } - sort.Strings(ret) - return ret -} - func main() { if len(os.Args) != 3 { _, _ = fmt.Fprintf(os.Stderr, "Usage: %s TLS-file crt.sh-file\n", os.Args[0]) @@ -129,7 +119,7 @@ func mainWithError(filenameTLS string, filenameCrtSh string) error { if err != nil { return fmt.Errorf("could load TLS file: %w", err) } - hostsTLS := keys(certsTLS) + hostsTLS := slices.Sorted(maps.Keys(certsTLS)) certsCrtSh, err := readCrtSh(filenameCrtSh, hostsTLS) if err != nil { return fmt.Errorf("could load crt.sh file: %w", err) diff --git a/bin-src/tls-pem2html.go b/bin-src/tls-pem2html.go index dcf22ba..ffb3416 100644 --- a/bin-src/tls-pem2html.go +++ b/bin-src/tls-pem2html.go @@ -100,24 +100,6 @@ func (cert Cert) Class() string { } } -type Certs []Cert - -// Len is the number of elements in the collection. -func (l Certs) Len() int { - return len(l) -} - -// Less reports whether the element with -// index i should sort before the element with index j. -func (l Certs) Less(i, j int) bool { - return l[i].X509.NotAfter.After(l[j].X509.NotAfter) -} - -// Swap swaps the elements with indexes i and j. -func (l Certs) Swap(i, j int) { - l[i], l[j] = l[j], l[i] -} - func main() { if err := mainWithError(); err != nil { _, _ = fmt.Fprintf(os.Stderr, "%s: error: %v", os.Args[0], err) @@ -131,7 +113,7 @@ func mainWithError() error { return fmt.Errorf("reading stdin: %w", err) } - var certs Certs + var certs []Cert for len(data) > 0 { var certPem *pem.Block certPem, data = pem.Decode(data) @@ -154,7 +136,9 @@ func mainWithError() error { certs = append(certs, cert) } - sort.Sort(certs) + sort.Slice(certs, func(i, j int) bool { + return certs[i].X509.NotAfter.After(certs[j].X509.NotAfter) + }) if err := tmpl.Execute(os.Stdout, map[string]any{"certs": certs, "now": now}); err != nil { return fmt.Errorf("executing template: %w", err) } |