[#13] services/util: Support server-side stream request verify

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-25 16:01:16 +03:00 committed by Alex Vanin
parent c378c353d5
commit da1961cdf9

View file

@ -23,7 +23,26 @@ func NewUnarySignService(key *ecdsa.PrivateKey, handler UnaryHandler) *UnarySign
}
}
func (s *UnarySignService) HandleServerStreamRequest(ctx context.Context, req interface{}) (interface{}, error) {
return s.verifyAndProc(ctx, req)
}
func (s *UnarySignService) HandleUnaryRequest(ctx context.Context, req interface{}) (interface{}, error) {
// verify and process request
resp, err := s.verifyAndProc(ctx, req)
if err != nil {
return nil, err
}
// sign the response
if err := signature.SignServiceMessage(s.key, resp); err != nil {
return nil, errors.Wrap(err, "could not sign response")
}
return resp, nil
}
func (s *UnarySignService) verifyAndProc(ctx context.Context, req interface{}) (interface{}, error) {
// verify request signatures
if err := signature.VerifyServiceMessage(req); err != nil {
return nil, errors.Wrap(err, "could not verify request")
@ -35,10 +54,5 @@ func (s *UnarySignService) HandleUnaryRequest(ctx context.Context, req interface
return nil, errors.Wrap(err, "could not handle request")
}
// sign the response
if err := signature.SignServiceMessage(s.key, resp); err != nil {
return nil, errors.Wrap(err, "could not sign response")
}
return resp, nil
}