  {
  	MBuf	   *src,
  			   *dst;
-@@ -480,22 +519,46 @@ encrypt_internal(int is_pubenc, int is_text,
+@@ -480,22 +520,46 @@ encrypt_internal(int is_pubenc, int is_text,
  		MBuf	   *kbuf = create_mbuf_from_vardata(key);
  
  		err = pgp_set_pubkey(ctx, kbuf,

+	if (res < 0)
+		goto out;
+
+	res = extract_signature_keys(ctx, pf_prefix, opaque, sig_key_cb, 1);
+
+out:
+	if (pf_prefix)

 /*
  * Wrappers for public-key functions
  */
@@ -745,7 +1105,7 @@ pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS)
 	if (PG_NARGS() > 2)
 		arg = PG_GETARG_BYTEA_P(2);
 
