goutils/cmd/pembody/pembody.go

38 lines
604 B
Go
Raw Normal View History

2015-09-22 17:39:27 +00:00
package main
import (
"encoding/pem"
"flag"
"fmt"
"io/ioutil"
"os"
2015-09-22 17:39:27 +00:00
2020-11-27 04:09:37 +00:00
"git.sr.ht/~kisom/goutils/lib"
2015-09-22 17:39:27 +00:00
)
func main() {
flag.Parse()
if flag.NArg() != 1 {
lib.Errx(lib.ExitFailure, "a single filename is required")
}
var in []byte
var err error
path := flag.Arg(0)
if path == "-" {
in, err = ioutil.ReadAll(os.Stdin)
} else {
in, err = ioutil.ReadFile(flag.Arg(0))
}
2015-09-22 17:39:27 +00:00
if err != nil {
lib.Err(lib.ExitFailure, err, "couldn't read file")
}
p, _ := pem.Decode(in)
if p == nil {
lib.Errx(lib.ExitFailure, "%s isn't a PEM-encoded file", flag.Arg(0))
}
fmt.Printf("%s", p.Bytes)
}