From 10137b44dd86c6d677da8fd886f70fbcefe6fdf9 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 25 Aug 2020 14:47:55 +0300 Subject: [PATCH] [#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 --- v2/signature/sign.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/v2/signature/sign.go b/v2/signature/sign.go index 8adaf3e..4e7bd23 100644 --- a/v2/signature/sign.go +++ b/v2/signature/sign.go @@ -30,8 +30,8 @@ type stableMarshaler interface { StableSize() int } -type stableMarshalerWrapper struct { - sm stableMarshaler +type StableMarshalerWrapper struct { + SM stableMarshaler } type metaHeader interface { @@ -113,17 +113,17 @@ func (r *responseVerificationHeader) setOrigin(m stableMarshaler) { } } -func (s stableMarshalerWrapper) ReadSignedData(buf []byte) ([]byte, error) { - if s.sm != nil { - return s.sm.StableMarshal(buf) +func (s StableMarshalerWrapper) ReadSignedData(buf []byte) ([]byte, error) { + if s.SM != nil { + return s.SM.StableMarshal(buf) } return nil, nil } -func (s stableMarshalerWrapper) SignedDataSize() int { - if s.sm != nil { - return s.sm.StableSize() +func (s StableMarshalerWrapper) SignedDataSize() int { + if s.SM != nil { + return s.SM.StableSize() } return 0 @@ -210,7 +210,7 @@ func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrit // sign part if err := signature.SignDataWithHandler( key, - &stableMarshalerWrapper{part}, + &StableMarshalerWrapper{part}, keySignatureHandler(sig), ); err != nil { return err @@ -282,7 +282,7 @@ func verifyMatryoshkaLevel(body stableMarshaler, meta metaHeader, verify verific func verifyServiceMessagePart(part stableMarshaler, sigRdr func() *refs.Signature) error { return signature.VerifyDataWithSource( - &stableMarshalerWrapper{part}, + &StableMarshalerWrapper{part}, keySignatureSource(sigRdr()), ) }