go-cert-thing/show.go

45 lines
631 B
Go
Raw Normal View History

2024-06-05 14:01:17 -07:00
package main
import (
"fmt"
"os"
"encoding/pem"
"crypto/x509"
"github.com/alexflint/go-arg"
)
func run(args *Arguments) error {
raw, err := os.ReadFile(args.Input)
if err != nil {
return err
}
block, rest := pem.Decode(raw)
fmt.Println(block.Type)
fmt.Println("len(rest):", len(rest))
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return err
}
fmt.Println(cert)
return nil
}
type Arguments struct {
Input string `arg:"positional,required"`
}
func main() {
args := &Arguments{}
arg.MustParse(args)
err := run(args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}