Skip to content

Commit

Permalink
parse timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
encbladexp committed Sep 28, 2024
1 parent 4921604 commit e409d21
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import (
"encoding/csv"
"fmt"
"os"
"time"
)

const FILENAME = "index.txt"
const TIMEFORMAT = "060102150405Z"
const (
CERT_STATUS = iota
CERT_EXPIRED
CERT_REVOKED
CERT_SERIAL
CERT_FILENAME
CERT_CN
)

type Certificate struct {
Status string
Expired string
Revoked string
Expired time.Time
Revoked time.Time
Serial string
Filename string
CN string
Expand All @@ -19,19 +31,37 @@ type Certificates struct {
Certificates []Certificate
}

func (c *Certificates) process_line(line []string) {
cert := Certificate{
line[0],
line[1],
line[2],
line[3],
line[4],
line[5],
func (c Certificates) parse_time(timestring string) (*time.Time, error) {
date, err := time.Parse(TIMEFORMAT, timestring) // TODO: Short and Long Timeformat
if err != nil {
return nil, err
}
c.Certificates = append(c.Certificates, cert)
return &date, nil
}

const FILENAME = "index.txt"
func (c *Certificates) process_line(line []string) {
cert := Certificate{}
expired, err := c.parse_time(line[CERT_EXPIRED])
if err != nil {
panic(err)
}
cert.Expired = *expired
revoked_string := line[CERT_REVOKED]
if revoked_string != "" {
revoked, err := c.parse_time(line[CERT_REVOKED])
if err != nil {
panic(err)
}
cert.Revoked = *revoked
}
cert.Status = line[CERT_STATUS]
cert.Filename = line[CERT_FILENAME]
cert.Serial = line[CERT_SERIAL]
switch cert.Status {
case "V":
c.Certificates = append(c.Certificates, cert)
}
}

func main() {
file, err := os.Open(FILENAME)
Expand Down

0 comments on commit e409d21

Please sign in to comment.