public function testSearchRemoteKeys(){ $gpg = new \Core\GPG\GPG(); $keys = $gpg->searchRemoteKeys($this->key); $this->assertTrue(is_array($keys), 'GPG->searchRemoteKeys did not return an array!'); if(sizeof($keys) == 0){ $this->markTestSkipped('Unable to perform test, GPG key ' . $this->key . ' was not located on remote keyservers!'); } foreach($keys as $k){ $this->assertInstanceOf('Core\\GPG\\PrimaryKey', $k); /** @var Core\GPG\PrimaryKey $k */ if(($uid = $k->getUID($this->email))){ // It's the key we're wanting! $this->assertEquals($this->key, $k->id_short); $this->assertEquals($this->bits, $k->encryptionBits); $this->assertEquals($this->enc, $k->encryptionType); $this->assertEquals($this->name, $uid->fullname); $this->assertEquals($this->email, $uid->email); $this->assertEquals($this->comment, $uid->comment); } } }
/** * Get an array of keys to install automatically with this repo. * * @return array */ public function getKeys(){ if($this->_keys !== null){ // Cache! return $this->_keys; } $gpg = new \Core\GPG\GPG(); $this->_keys = []; foreach($this->getElements('keys/key') as $k){ $id = $k->getAttribute('id'); $key = null; $local = true; // Try to find more info about this key! // First step is to assign the key from local data. // If that fails, gracefully search remote servers for it. if(($key = $gpg->getKey($id)) === null){ $remoteKeys = $gpg->searchRemoteKeys($id); foreach($remoteKeys as $k){ /** @var \Core\GPG\PublicKey $k */ if($k->id == $id || $k->id_short == $id){ $key = $k; $local = false; break; } } } if($key !== null){ $dat = [ 'key' => $id, 'available' => true, 'installed' => $local, 'fingerprint' => \Core\GPG\GPG::FormatFingerprint($key->fingerprint, false, true), 'uids' => [], ]; foreach($key->uids as $uid){ /** @var \Core\GPG\UID $uid */ if($uid->isValid()){ $dat['uids'][] = ['name' => $uid->fullname, 'email' => $uid->email]; } } } else{ $dat = [ 'key' => $id, 'available' => false, 'installed' => false, 'fingerprint' => '', 'uids' => [], ]; } $this->_keys[] = $dat; } return $this->_keys; }