pkg/inspect: add YAML and JSON marshallers

This commit is contained in:
Laurence Withers 2023-04-29 10:56:58 +01:00
parent 9c12d15bfb
commit 279e9af791
2 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"crypto/x509"
"encoding/binary"
"errors"
"strconv"
"strings"
)
@ -125,6 +126,16 @@ func (f Fingerprint) String() string {
return FormatHexBytes([]byte(f))
}
// MarshalJSON returns a quoted hex string.
func (f Fingerprint) MarshalJSON() ([]byte, error) {
return strconv.AppendQuote(nil, FormatHexBytes([]byte(f))), nil
}
// MarshalYAML returns a hex string.
func (f Fingerprint) MarshalYAML() (any, error) {
return FormatHexBytes([]byte(f)), nil
}
const hexDig = "0123456789ABCDEF"
// FormatHexBytes returns a nicely-formatted hex string that is easy to read/compare.

View File

@ -3,6 +3,7 @@ package inspect
import (
"crypto/tls"
"fmt"
"strconv"
)
// ConnectionState returns a set of information about a TLS ConnectionState.
@ -47,6 +48,16 @@ func (ts TLSSecurity) String() string {
return "???"
}
// MarshalJSON returns a quoted string.
func (ts TLSSecurity) MarshalJSON() ([]byte, error) {
return strconv.AppendQuote(nil, ts.String()), nil
}
// MarshalYAML returns a string.
func (ts TLSSecurity) MarshalYAML() (any, error) {
return ts.String(), nil
}
// TLSConnectionState holds structured information about a negotiated TLS
// connection. It does not include the peer's certificate information.
type TLSConnectionState struct {