Add pem2bin, a utility for dumping the contents of PEM blocks.
This commit is contained in:
39
cmd/pem2bin/main.go
Normal file
39
cmd/pem2bin/main.go
Normal file
@@ -0,0 +1,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user