diff --git a/go/common/crypto/signature/signers/remote/grpc.go b/go/common/crypto/signature/signers/remote/grpc.go index cebd48b5f65..1a9ee9847e8 100644 --- a/go/common/crypto/signature/signers/remote/grpc.go +++ b/go/common/crypto/signature/signers/remote/grpc.go @@ -26,7 +26,7 @@ var ( serviceDesc = grpc.ServiceDesc{ ServiceName: string(serviceName), - HandlerType: (*wrapper)(nil), + HandlerType: (*Backend)(nil), Methods: []grpc.MethodDesc{ { MethodName: methodPublicKeys.ShortName(), @@ -53,11 +53,17 @@ type SignRequest struct { Message []byte `json:"message"` } +// Backend is the remote signer backend interface. +type Backend interface { + PublicKeys(context.Context) ([]PublicKey, error) + Sign(context.Context, *SignRequest) ([]byte, error) +} + type wrapper struct { signers map[signature.SignerRole]signature.Signer } -func (w *wrapper) publicKeys(ctx context.Context) ([]PublicKey, error) { +func (w *wrapper) PublicKeys(ctx context.Context) ([]PublicKey, error) { var resp []PublicKey for _, v := range signature.SignerRoles { // Return in consistent order. if signer := w.signers[v]; signer != nil { @@ -70,7 +76,7 @@ func (w *wrapper) publicKeys(ctx context.Context) ([]PublicKey, error) { return resp, nil } -func (w *wrapper) sign(ctx context.Context, req *SignRequest) ([]byte, error) { +func (w *wrapper) Sign(ctx context.Context, req *SignRequest) ([]byte, error) { signer, ok := w.signers[req.Role] if !ok { return nil, signature.ErrNotExist @@ -85,14 +91,14 @@ func handlerPublicKeys( // nolint: golint interceptor grpc.UnaryServerInterceptor, ) (interface{}, error) { if interceptor == nil { - return srv.(*wrapper).publicKeys(ctx) + return srv.(Backend).PublicKeys(ctx) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: methodPublicKeys.FullName(), } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(*wrapper).publicKeys(ctx) + return srv.(Backend).PublicKeys(ctx) } return interceptor(ctx, nil, info, handler) } @@ -108,14 +114,14 @@ func handlerSign( // nolint: golint return nil, err } if interceptor == nil { - return srv.(*wrapper).sign(ctx, &req) + return srv.(Backend).Sign(ctx, &req) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: methodSign.FullName(), } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(*wrapper).sign(ctx, req.(*SignRequest)) + return srv.(Backend).Sign(ctx, req.(*SignRequest)) } return interceptor(ctx, &req, info, handler) } @@ -137,6 +143,7 @@ func RegisterService(server *grpc.Server, signerFactory signature.SignerFactory) w.signers[v] = signer } } + server.RegisterService(&serviceDesc, w) }