// Sign signs digest with the private key stored in Google's Cloud KMS.
Sign signs digest with the private key stored in Google's Cloud KMS.
// Sign signs digest with the private key stored in Google ' s Cloud KMS .
func (s *Signer) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
	req := &kmspb.AsymmetricSignRequest{
		Name:   s.signingKey,
		Digest: &kmspb.Digest{},
	}
	switch h := opts.HashFunc(); h {
	case crypto.SHA256:
		req.Digest.Digest = &kmspb.Digest_Sha256{
			Sha256: digest,
		}
	case crypto.SHA384:
		req.Digest.Digest = &kmspb.Digest_Sha384{
			Sha384: digest,
		}
	case crypto.SHA512:
		req.Digest.Digest = &kmspb.Digest_Sha512{
			Sha512: digest,
		}
	default:
		return nil, errors.Errorf("unsupported hash function %v", h)
	}
	ctx, cancel := defaultContext()
	defer cancel()
	response, err := s.client.AsymmetricSign(ctx, req)
	if err != nil {
		return nil, errors.Wrap(err, "cloudKMS AsymmetricSign failed")
	}
	return response.Signature, nil
}
func ( s * Signer ) Sign ( rand io . Reader , digest [ ] byte , opts crypto . SignerOpts ) ( [ ] byte , error ) { req := & kmspb . AsymmetricSignRequest { Name : s . signingKey , Digest : & kmspb . Digest { } , } switch h := opts . HashFunc ( ) ; h { case crypto . SHA256 : req . Digest . Digest = & kmspb . Digest_Sha256 { Sha256 : digest , } case crypto . SHA384 : req . Digest . Digest = & kmspb . Digest_Sha384 { Sha384 : digest , } case crypto . SHA512 : req . Digest . Digest = & kmspb . Digest_Sha512 { Sha512 : digest , } default : return nil , errors . Errorf ( " " , h ) } ctx , cancel := defaultContext ( ) defer cancel ( ) response , err := s . client . AsymmetricSign ( ctx , req ) if err != nil { return nil , errors . Wrap ( err , " " ) } return response . Signature , nil }
Sign signs digest with the private key stored in Google's Cloud KMS.
Sign signs digest with the private key stored in Google ' s Cloud KMS .