[#126] v2: make stable marshal wrapper public

This wrapper can be used outside of v2 packages to
use SignDataWithHandler function. This function uses
DataSource interface and this wrapper implements
this interface based on stable marshal structures.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-08-25 14:47:55 +03:00 committed by Stanislav Bogatyrev
parent 8c920d75a6
commit 10137b44dd

View file

@ -30,8 +30,8 @@ type stableMarshaler interface {
StableSize() int StableSize() int
} }
type stableMarshalerWrapper struct { type StableMarshalerWrapper struct {
sm stableMarshaler SM stableMarshaler
} }
type metaHeader interface { type metaHeader interface {
@ -113,17 +113,17 @@ func (r *responseVerificationHeader) setOrigin(m stableMarshaler) {
} }
} }
func (s stableMarshalerWrapper) ReadSignedData(buf []byte) ([]byte, error) { func (s StableMarshalerWrapper) ReadSignedData(buf []byte) ([]byte, error) {
if s.sm != nil { if s.SM != nil {
return s.sm.StableMarshal(buf) return s.SM.StableMarshal(buf)
} }
return nil, nil return nil, nil
} }
func (s stableMarshalerWrapper) SignedDataSize() int { func (s StableMarshalerWrapper) SignedDataSize() int {
if s.sm != nil { if s.SM != nil {
return s.sm.StableSize() return s.SM.StableSize()
} }
return 0 return 0
@ -210,7 +210,7 @@ func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrit
// sign part // sign part
if err := signature.SignDataWithHandler( if err := signature.SignDataWithHandler(
key, key,
&stableMarshalerWrapper{part}, &StableMarshalerWrapper{part},
keySignatureHandler(sig), keySignatureHandler(sig),
); err != nil { ); err != nil {
return err return err
@ -282,7 +282,7 @@ func verifyMatryoshkaLevel(body stableMarshaler, meta metaHeader, verify verific
func verifyServiceMessagePart(part stableMarshaler, sigRdr func() *refs.Signature) error { func verifyServiceMessagePart(part stableMarshaler, sigRdr func() *refs.Signature) error {
return signature.VerifyDataWithSource( return signature.VerifyDataWithSource(
&stableMarshalerWrapper{part}, &StableMarshalerWrapper{part},
keySignatureSource(sigRdr()), keySignatureSource(sigRdr()),
) )
} }