From 16b2dbbc48b73bd5053107cc2cc6192b2dfdac0a Mon Sep 17 00:00:00 2001 From: Andrei Burdulescu Date: Sat, 21 Jan 2023 22:39:51 +0200 Subject: [PATCH] rsa-pem-der: Print hex by default, bin via flag --- cmd_rsa_pem_der.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd_rsa_pem_der.go b/cmd_rsa_pem_der.go index 416722f..1118278 100644 --- a/cmd_rsa_pem_der.go +++ b/cmd_rsa_pem_der.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "encoding/hex" "encoding/pem" "errors" "flag" @@ -28,6 +29,7 @@ Options: fOutput := fset.String("out", "", "Write the result to the file at path OUTPUT.") fInput := fset.String("in", "", "Read data from the file at path INPUT.") + fPrintBin := fset.Bool("bin", false, "Print output in binary form.") if err := fset.Parse(args); err != nil { return err @@ -67,8 +69,12 @@ Options: return errors.New("failed to parse PEM block") } - if _, err := io.Copy(w, bytes.NewBuffer(block.Bytes)); err != nil { - return err + if *fPrintBin { + if _, err := io.Copy(w, bytes.NewBuffer(block.Bytes)); err != nil { + return err + } + } else { + fmt.Fprintln(w, hex.EncodeToString(block.Bytes)) } return nil