diff --git a/pkg/checksum.go b/pkg/checksum.go index 59ece9d1..d8a91b7b 100644 --- a/pkg/checksum.go +++ b/pkg/checksum.go @@ -28,6 +28,8 @@ const ( ) // NewChecksumFromV2 wraps v2 Checksum message to Checksum. +// +// Nil refs.Checksum converts to nil. func NewChecksumFromV2(cV2 *refs.Checksum) *Checksum { return (*Checksum)(cV2) } @@ -72,6 +74,9 @@ func (c *Checksum) SetTillichZemor(v [64]byte) { checksum.SetSum(v[:]) } +// ToV2 converts Checksum to v2 Checksum message. +// +// Nil Checksum converts to nil. func (c *Checksum) ToV2() *refs.Checksum { return (*refs.Checksum)(c) } diff --git a/pkg/checksum_test.go b/pkg/checksum_test.go index e636f403..04343a92 100644 --- a/pkg/checksum_test.go +++ b/pkg/checksum_test.go @@ -99,3 +99,19 @@ func TestChecksumEncoding(t *testing.T) { require.Equal(t, cs, cs2) }) } + +func TestNewChecksumFromV2(t *testing.T) { + t.Run("from nil", func(t *testing.T) { + var x *refs.Checksum + + require.Nil(t, NewChecksumFromV2(x)) + }) +} + +func TestChecksum_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *Checksum + + require.Nil(t, x.ToV2()) + }) +}