diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-02-23 11:59:46 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-02-23 11:59:46 +0100 |
commit | b4dd74a3f36ca46b7bcda69e8d95949babfeb76d (patch) | |
tree | 6f3cbe32be4e675ba385e2575e28cf7a0f4dca00 /types/serialize.go | |
parent | 1505c6db8e0e66d88a645ac5cc36647a6f8b2f43 (diff) |
renamed and reordered to improve readability
Diffstat (limited to 'types/serialize.go')
-rw-r--r-- | types/serialize.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/types/serialize.go b/types/serialize.go new file mode 100644 index 0000000..da4bd9f --- /dev/null +++ b/types/serialize.go @@ -0,0 +1,28 @@ +package types + +import ( + "fmt" + + "github.com/google/certificate-transparency-go/tls" +) + +// Marshal marshals a TLS-encodable structure +func Marshal(item interface{}) ([]byte, error) { + serialized, err := tls.Marshal(item) + if err != nil { + return nil, fmt.Errorf("tls.Marshal: %v", err) + } + return serialized, nil +} + +// Unmarshal unmarshals a TLS-encoded structure +func Unmarshal(serialized []byte, out interface{}) error { + extra, err := tls.Unmarshal(serialized, out) + if err != nil { + return fmt.Errorf("tls.Unmarshal: %v", err) + } + if len(extra) > 0 { + return fmt.Errorf("tls.Unmarshal: extra data: %X", extra) + } + return nil +} |