}
public static function getService($links, $service) {
+ if (!is_array($links)) {
+ return false;
+ }
+
foreach ($links as $link) {
if ($link['rel'] == $service) {
return $link;
{
$disco = new Discovery();
- $xrd = $disco->lookup($signer_uri);
- if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
- list($type, $keypair) = explode(';', $link['href']);
- return $keypair;
+ try {
+ $xrd = $disco->lookup($signer_uri);
+ } catch (Exception $e) {
+ return false;
+ }
+ if ($xrd->links) {
+ if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
+ list($type, $keypair) = explode(';', $link['href']);
+ return $keypair;
+ }
}
-
throw new Exception('Unable to locate signer public key');
}
throw new Exception("Unable to determine entry author.");
}
- $signature_alg = Magicsig::fromString($this->getKeyPair($signer_uri));
+ $keypair = $this->getKeyPair($signer_uri);
+ if (!$keypair) {
+ throw new Exception("Unable to retrive keypair for ". $signer_uri);
+ }
+ $signature_alg = Magicsig::fromString($keypair);
$armored_text = base64_encode($text);
return array(