forked from TrueCloudLab/frostfs-node
[#13] services/util: Support server-side stream request verify
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>support/v0.27
parent
c378c353d5
commit
da1961cdf9
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue