| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\GnupgException; |
| 6 |
|
| 7 |
/** |
| 8 |
* |
| 9 |
* |
| 10 |
* @param resource $identifier The gnupg identifier, from a call to |
| 11 |
* gnupg_init or gnupg. |
| 12 |
* @param string $fingerprint The fingerprint key. |
| 13 |
* @param string $passphrase The pass phrase. |
| 14 |
* @throws GnupgException |
| 15 |
* |
| 16 |
*/ |
| 17 |
function gnupg_adddecryptkey($identifier, string $fingerprint, string $passphrase): void |
| 18 |
{ |
| 19 |
error_clear_last(); |
| 20 |
$result = \gnupg_adddecryptkey($identifier, $fingerprint, $passphrase); |
| 21 |
if ($result === false) { |
| 22 |
throw GnupgException::createFromPhpError(); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* |
| 29 |
* |
| 30 |
* @param resource $identifier The gnupg identifier, from a call to |
| 31 |
* gnupg_init or gnupg. |
| 32 |
* @param string $fingerprint The fingerprint key. |
| 33 |
* @throws GnupgException |
| 34 |
* |
| 35 |
*/ |
| 36 |
function gnupg_addencryptkey($identifier, string $fingerprint): void |
| 37 |
{ |
| 38 |
error_clear_last(); |
| 39 |
$result = \gnupg_addencryptkey($identifier, $fingerprint); |
| 40 |
if ($result === false) { |
| 41 |
throw GnupgException::createFromPhpError(); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* |
| 48 |
* |
| 49 |
* @param resource $identifier The gnupg identifier, from a call to |
| 50 |
* gnupg_init or gnupg. |
| 51 |
* @param string $fingerprint The fingerprint key. |
| 52 |
* @param string|null $passphrase The pass phrase. |
| 53 |
* |
| 54 |
* @throws GnupgException |
| 55 |
* |
| 56 |
*/ |
| 57 |
function gnupg_addsignkey($identifier, string $fingerprint, ?string $passphrase = null): void |
| 58 |
{ |
| 59 |
error_clear_last(); |
| 60 |
if ($passphrase !== null) { |
| 61 |
$result = \gnupg_addsignkey($identifier, $fingerprint, $passphrase); |
| 62 |
} else { |
| 63 |
$result = \gnupg_addsignkey($identifier, $fingerprint); |
| 64 |
} |
| 65 |
if ($result === false) { |
| 66 |
throw GnupgException::createFromPhpError(); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
/** |
| 72 |
* |
| 73 |
* |
| 74 |
* @param resource $identifier The gnupg identifier, from a call to |
| 75 |
* gnupg_init or gnupg. |
| 76 |
* @throws GnupgException |
| 77 |
* |
| 78 |
*/ |
| 79 |
function gnupg_cleardecryptkeys($identifier): void |
| 80 |
{ |
| 81 |
error_clear_last(); |
| 82 |
$result = \gnupg_cleardecryptkeys($identifier); |
| 83 |
if ($result === false) { |
| 84 |
throw GnupgException::createFromPhpError(); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
/** |
| 90 |
* |
| 91 |
* |
| 92 |
* @param resource $identifier The gnupg identifier, from a call to |
| 93 |
* gnupg_init or gnupg. |
| 94 |
* @throws GnupgException |
| 95 |
* |
| 96 |
*/ |
| 97 |
function gnupg_clearencryptkeys($identifier): void |
| 98 |
{ |
| 99 |
error_clear_last(); |
| 100 |
$result = \gnupg_clearencryptkeys($identifier); |
| 101 |
if ($result === false) { |
| 102 |
throw GnupgException::createFromPhpError(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* |
| 109 |
* |
| 110 |
* @param resource $identifier The gnupg identifier, from a call to |
| 111 |
* gnupg_init or gnupg. |
| 112 |
* @throws GnupgException |
| 113 |
* |
| 114 |
*/ |
| 115 |
function gnupg_clearsignkeys($identifier): void |
| 116 |
{ |
| 117 |
error_clear_last(); |
| 118 |
$result = \gnupg_clearsignkeys($identifier); |
| 119 |
if ($result === false) { |
| 120 |
throw GnupgException::createFromPhpError(); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
/** |
| 126 |
* Toggle the armored output. |
| 127 |
* |
| 128 |
* @param resource $identifier The gnupg identifier, from a call to |
| 129 |
* gnupg_init or gnupg. |
| 130 |
* @param int $armor Pass a non-zero integer-value to this function to enable armored-output |
| 131 |
* (default). |
| 132 |
* Pass 0 to disable armored output. |
| 133 |
* @throws GnupgException |
| 134 |
* |
| 135 |
*/ |
| 136 |
function gnupg_setarmor($identifier, int $armor): void |
| 137 |
{ |
| 138 |
error_clear_last(); |
| 139 |
$result = \gnupg_setarmor($identifier, $armor); |
| 140 |
if ($result === false) { |
| 141 |
throw GnupgException::createFromPhpError(); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
/** |
| 147 |
* Sets the mode for signing. |
| 148 |
* |
| 149 |
* @param resource $identifier The gnupg identifier, from a call to |
| 150 |
* gnupg_init or gnupg. |
| 151 |
* @param int $signmode The mode for signing. |
| 152 |
* |
| 153 |
* signmode takes a constant indicating what type of |
| 154 |
* signature should be produced. The possible values are |
| 155 |
* GNUPG_SIG_MODE_NORMAL, |
| 156 |
* GNUPG_SIG_MODE_DETACH and |
| 157 |
* GNUPG_SIG_MODE_CLEAR. |
| 158 |
* By default GNUPG_SIG_MODE_CLEAR is used. |
| 159 |
* @throws GnupgException |
| 160 |
* |
| 161 |
*/ |
| 162 |
function gnupg_setsignmode($identifier, int $signmode): void |
| 163 |
{ |
| 164 |
error_clear_last(); |
| 165 |
$result = \gnupg_setsignmode($identifier, $signmode); |
| 166 |
if ($result === false) { |
| 167 |
throw GnupgException::createFromPhpError(); |
| 168 |
} |
| 169 |
} |
| 170 |
|