Skip to content

Commit 84a97d0

Browse files
authored
Key editing tool (#43)
1 parent f300cc7 commit 84a97d0

5 files changed

Lines changed: 801 additions & 3 deletions

File tree

Crypt/GPG.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ class Crypt_GPG extends Crypt_GPGAbstract
235235
*/
236236
protected $passphrases = [];
237237

238+
/**
239+
* Get a key editor instance
240+
*
241+
* @return Crypt_GPG_KeyEditor Key editor object
242+
*/
243+
public function getKeyEditor()
244+
{
245+
return $this->engine->getKeyEditor();
246+
}
247+
238248
/**
239249
* Imports a public or private key into the keyring
240250
*

Crypt/GPG/Engine.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
*/
6060
require_once 'Crypt/GPG/SignatureCreationInfo.php';
6161

62+
/**
63+
* Key editor
64+
*/
65+
require_once 'Crypt/GPG/KeyEditor.php';
66+
6267
/**
6368
* Standard PEAR exception is used if GPG binary is not found.
6469
*/
@@ -999,6 +1004,29 @@ public function setProcessData($name, $value)
9991004
}
10001005
}
10011006

1007+
/**
1008+
* Initialize key editor instance
1009+
*
1010+
* @return Crypt_GPG_KeyEditor Key editor object
1011+
*/
1012+
public function getKeyEditor()
1013+
{
1014+
$keys = ['homedir', 'binary', 'publicKeyring', 'privateKeyring', 'trustDb'];
1015+
$options = [];
1016+
1017+
foreach ($keys as $key) {
1018+
if (isset($this->{"_{$key}"})) {
1019+
$options[$key] = $this->{"_{$key}"};
1020+
}
1021+
}
1022+
1023+
if ($this->_debug) {
1024+
$options['debug'] = function ($line) { $this->_debug($line); };
1025+
}
1026+
1027+
return new Crypt_GPG_KeyEditor($this, $options);
1028+
}
1029+
10021030
/**
10031031
* Displays debug output for status lines
10041032
*

Crypt/GPG/Key.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getUserIds()
108108
*
109109
* The primary key is the first added sub-key.
110110
*
111-
* @return Crypt_GPG_SubKey the primary sub-key of this key.
111+
* @return ?Crypt_GPG_SubKey the primary sub-key of this key.
112112
*/
113113
public function getPrimaryKey()
114114
{
@@ -166,7 +166,7 @@ public function canEncrypt()
166166
*
167167
* @param Crypt_GPG_SubKey $subKey the sub-key to add.
168168
*
169-
* @return Crypt_GPG_Key the current object, for fluent interface.
169+
* @return $this the current object, for fluent interface.
170170
*/
171171
public function addSubKey(Crypt_GPG_SubKey $subKey)
172172
{
@@ -179,7 +179,7 @@ public function addSubKey(Crypt_GPG_SubKey $subKey)
179179
*
180180
* @param Crypt_GPG_UserId $userId the user id to add.
181181
*
182-
* @return Crypt_GPG_Key the current object, for fluent interface.
182+
* @return $this the current object, for fluent interface.
183183
*/
184184
public function addUserId(Crypt_GPG_UserId $userId)
185185
{

0 commit comments

Comments
 (0)