[#302] pkg/checksum: Convert nil Checksum to nil message

Document that `Checksum.ToV2` method return `nil`
when called on `nil`. Document that `NewChecksumFromV2`
function return `nil` when called on `nil`. Write
corresponding unit tests.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 21:02:30 +03:00 committed by Alex Vanin
parent 245271bb65
commit 35b6629e1c
2 changed files with 21 additions and 0 deletions

View file

@ -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)
}