diff --git a/main.go b/main.go index 082034d..f0f837a 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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)