[#302] pkg/signature: Convert nil Signature to nil message

Document that `Signature.ToV2` method return `nil`
when called on `nil`. Document that `NewSignatureFromV2`
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:12:17 +03:00 committed by Alex Vanin
parent bf0d106e54
commit b506970636
2 changed files with 22 additions and 0 deletions

View file

@ -8,6 +8,8 @@ import (
type Signature refs.Signature
// NewSignatureFromV2 wraps v2 Signature message to Signature.
//
// Nil refs.Signature converts to nil.
func NewSignatureFromV2(sV2 *refs.Signature) *Signature {
return (*Signature)(sV2)
}
@ -39,6 +41,9 @@ func (s *Signature) SetSign(v []byte) {
(*refs.Signature)(s).SetSign(v)
}
// ToV2 converts Signature to v2 Signature message.
//
// Nil Signature converts to nil.
func (s *Signature) ToV2() *refs.Signature {
return (*refs.Signature)(s)
}