Skip to content

Commit ba5b431

Browse files
Add PEM export functionality (#59)
2 parents a189dee + 20b60a0 commit ba5b431

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ File Location Subject
9797
Found 140 certificates
9898
```
9999

100-
### Global flags
100+
The `--output` (or `-o`) flag allows specifying the output mode for export.
101+
102+
- `--output pretty` is the default, and gives a table view of the data.
103+
- `--output wide` also uses a table layout, but includes more infomation.
104+
- `--output json` emits JSON.
105+
- `--output pem` emits all full certificates in PEM format.
101106

102-
`-o --output`: Allows specification of the output mode. Supports `pretty`, `wide`, and `json`. Defaults to `pretty`.
107+
### Global flags
103108

104109
`--platform`: Specifies the platform in the form `os/arch[/variant][:osversion]` (e.g. `linux/amd64`)
105110

cmd/export.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"context"
77
"encoding/hex"
88
"encoding/json"
9+
"encoding/pem"
910
"fmt"
11+
"os"
1012
"time"
1113

1214
"github.com/fatih/color"
@@ -119,6 +121,13 @@ func newExport(ctx context.Context) *cobra.Command {
119121
}
120122

121123
fmt.Println(string(m))
124+
} else if outOpts.Mode == options.OutputModePEM {
125+
for _, cert := range parsedCertificates.Found {
126+
pem.Encode(os.Stdout, &pem.Block{
127+
Type: "CERTIFICATE",
128+
Bytes: cert.Certificate.Raw,
129+
})
130+
}
122131
}
123132

124133
return nil

cmd/options/outputs.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ const (
1313
OutputModePretty = "pretty"
1414
OutputModeJSON = "json"
1515
OutputModeWide = "wide"
16+
OutputModePEM = "pem"
1617
)
1718

18-
var outputModes = []string{OutputModePretty, OutputModeJSON, OutputModeWide}
19+
var outputModes = []string{
20+
OutputModePretty,
21+
OutputModeJSON,
22+
OutputModeWide,
23+
OutputModePEM,
24+
}
1925

2026
// Output are options for configuring command outputs.
2127
type Output struct {

0 commit comments

Comments
 (0)