File: main.go

package info (click to toggle)
golang-github-kisom-goutils 0.0~git20161101.0.858c9cb-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 396 kB
  • sloc: makefile: 6
file content (39 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (4)
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
38
39
package main

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

var ext = ".bin"

func stripPEM(path string) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}

	p, rest := pem.Decode(data)
	if len(rest) != 0 {
		fmt.Fprintf(os.Stderr, "[WARNING] extra data in PEM file\n")
		fmt.Fprintf(os.Stderr, "          (only the first object will be decoded)\n")
	}

	return ioutil.WriteFile(path+ext, p.Bytes, 0644)
}

func main() {
	flag.Parse()

	for _, path := range flag.Args() {
		err := stripPEM(path)
		if err != nil {
			fmt.Fprintf(os.Stderr, "processing %s failed: %v\n", path, err)
		} else {
			fmt.Println(path, "->", path+ext)
		}
	}
}