Skip to content

Commit

Permalink
rsa-pem-der: Print hex by default, bin via flag
Browse files Browse the repository at this point in the history
  • Loading branch information
aburdulescu committed Jan 21, 2023
1 parent d98d71b commit 16b2dbb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd_rsa_pem_der.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"encoding/hex"
"encoding/pem"
"errors"
"flag"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16b2dbb

Please sign in to comment.