Skip to content

Instantly share code, notes, and snippets.

@tksk
Created November 2, 2012 17:50
Show Gist options
  • Save tksk/4003116 to your computer and use it in GitHub Desktop.
Save tksk/4003116 to your computer and use it in GitHub Desktop.
gsk7cmd parser
Label:<label name>
Key Size: 1024
Version: X509 V3
Serial Number: 45 A0 C2 70 8D 77 8F 34 43 A1 5A C1 AE CB 62 DE
Issued By: VeriSign Class 3 Secure Server CA
VeriSign Trust Network
VeriSign, Inc.
US
Subject: xxx.com
<Organization name>
<Organization Info>
<C>
Valid From: Wednesday, December 16, 20XX 1:00:00 AM CET To: Friday, December 17, 20XX 12:59:59 AM CET
Fingerprint: 77:10:B7:DB:72:37:3A:72:5E:AA:A8:BA:DD:17:AB:46:F0:06:04:42
Signature Algorithm: 1.2.840.113549.1.1.5
Trust Status: enabled
#!/bin/env scala
!#
case class Cert(label: String, props: Map[String, String])
type KeyVals = (String, String)
def parseLine(lines: List[String]): List[KeyVals] = lines match {
case Nil => Nil
case x :: xs =>
val key :: headValue :: Nil = x.split(":", 2).toList
val (restValues, restLines) = xs.span(!_.contains(":"))
val value = (headValue.trim :: restValues).mkString(" ")
(key, value) :: parseLine(restLines)
}
val props = parseLine(io.Source.stdin.getLines.toList).toMap
println(Cert(props("Label"), props))
// vim: set ts=4 sw=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment