service/signature: Rename interface methods

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-12 18:20:04 +03:00 committed by Stanislav Bogatyrev
parent 746419e85f
commit 2ccfe34a20
3 changed files with 8 additions and 8 deletions

View file

@ -8,7 +8,7 @@ import (
type DataSource interface {
ReadSignedData([]byte) ([]byte, error)
SignedDataLength() int
SignedDataSize() int
}
type DataWithSignature interface {

View file

@ -7,8 +7,8 @@ import (
)
type SignedRequest interface {
Body() DataSource
MetaHeader() DataSource
RequestBody() DataSource
RequestMetaHeader() DataSource
OriginVerificationHeader() DataSource
SetBodySignatureWithKey(key, sig []byte)
@ -27,12 +27,12 @@ func SignRequest(key *ecdsa.PrivateKey, src SignedRequest) error {
}
// sign body
if err := SignDataWithHandler(key, src.Body(), src.SetBodySignatureWithKey); err != nil {
if err := SignDataWithHandler(key, src.RequestBody(), src.SetBodySignatureWithKey); err != nil {
return errors.Wrap(err, "could not sign body")
}
// sign meta
if err := SignDataWithHandler(key, src.Body(), src.SetMetaSignatureWithKey); err != nil {
if err := SignDataWithHandler(key, src.RequestMetaHeader(), src.SetMetaSignatureWithKey); err != nil {
return errors.Wrap(err, "could not sign meta header")
}
@ -46,12 +46,12 @@ func SignRequest(key *ecdsa.PrivateKey, src SignedRequest) error {
func VerifyRequest(src SignedRequest) error {
// verify body signature
if err := VerifyDataWithSource(src.Body(), src.BodySignatureWithKey); err != nil {
if err := VerifyDataWithSource(src.RequestBody(), src.BodySignatureWithKey); err != nil {
return errors.Wrap(err, "could not verify body")
}
// verify meta header
if err := VerifyDataWithSource(src.MetaHeader(), src.MetaSignatureWithKey); err != nil {
if err := VerifyDataWithSource(src.RequestMetaHeader(), src.MetaSignatureWithKey); err != nil {
return errors.Wrap(err, "could not verify meta header")
}

View file

@ -19,7 +19,7 @@ func dataForSignature(src DataSource) ([]byte, error) {
buf := bytesPool.Get().([]byte)
if size := src.SignedDataLength(); size < 0 {
if size := src.SignedDataSize(); size < 0 {
return nil, errors.New("negative length")
} else if size <= cap(buf) {
buf = buf[:size]