File: pembody.go

package info (click to toggle)
golang-github-kisom-goutils 0.0~git20161101.0.858c9cb-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 384 kB
  • ctags: 331
  • sloc: makefile: 6
file content (37 lines) | stat: -rw-r--r-- 604 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

import (
	"encoding/pem"
	"flag"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/kisom/goutils/lib"
)

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))
	}
	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)
}