pkg/inspect: add YAML and JSON marshallers
This commit is contained in:
parent
9c12d15bfb
commit
279e9af791
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue