summaryrefslogtreecommitdiff
path: root/plugins/OStatus/classes/Magicsig.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/OStatus/classes/Magicsig.php')
-rw-r--r--plugins/OStatus/classes/Magicsig.php30
1 files changed, 12 insertions, 18 deletions
diff --git a/plugins/OStatus/classes/Magicsig.php b/plugins/OStatus/classes/Magicsig.php
index f8c56a05f..20025c37a 100644
--- a/plugins/OStatus/classes/Magicsig.php
+++ b/plugins/OStatus/classes/Magicsig.php
@@ -31,23 +31,22 @@ require_once 'Crypt/RSA.php';
class Magicsig extends Memcached_DataObject
{
-
const PUBLICKEYREL = 'magic-public-key';
-
+
public $__table = 'magicsig';
public $user_id;
public $keypair;
public $alg;
-
+
public $publicKey;
public $privateKey;
-
+
public function __construct($alg = 'RSA-SHA256')
{
$this->alg = $alg;
}
-
+
public /*static*/ function staticGet($k, $v=null)
{
$obj = parent::staticGet(__CLASS__, $k, $v);
@@ -86,7 +85,6 @@ class Magicsig extends Memcached_DataObject
64, false));
}
-
function keys()
{
return array_keys($this->keyTypes());
@@ -111,7 +109,7 @@ class Magicsig extends Memcached_DataObject
public function generate($user_id)
{
$rsa = new Crypt_RSA();
-
+
$keypair = $rsa->createKey();
$rsa->loadKey($keypair['privatekey']);
@@ -121,12 +119,11 @@ class Magicsig extends Memcached_DataObject
$this->publicKey = new Crypt_RSA();
$this->publicKey->loadKey($keypair['publickey']);
-
+
$this->user_id = $user_id;
$this->insert();
}
-
public function toString($full_pair = true)
{
$mod = Magicsig::base64_url_encode($this->publicKey->modulus->toBytes());
@@ -136,13 +133,13 @@ class Magicsig extends Memcached_DataObject
$private_exp = '.' . Magicsig::base64_url_encode($this->privateKey->exponent->toBytes());
}
- return 'RSA.' . $mod . '.' . $exp . $private_exp;
+ return 'RSA.' . $mod . '.' . $exp . $private_exp;
}
-
+
public static function fromString($text)
{
$magic_sig = new Magicsig();
-
+
// remove whitespace
$text = preg_replace('/\s+/', '', $text);
@@ -150,7 +147,7 @@ class Magicsig extends Memcached_DataObject
if (!preg_match('/RSA\.([^\.]+)\.([^\.]+)(.([^\.]+))?/', $text, $matches)) {
return false;
}
-
+
$mod = $matches[1];
$exp = $matches[2];
if (!empty($matches[4])) {
@@ -184,7 +181,7 @@ class Magicsig extends Memcached_DataObject
$this->publicKey = $rsa;
}
}
-
+
public function getName()
{
return $this->alg;
@@ -197,9 +194,8 @@ class Magicsig extends Memcached_DataObject
case 'RSA-SHA256':
return 'sha256';
}
-
}
-
+
public function sign($bytes)
{
$sig = $this->privateKey->sign($bytes);
@@ -223,5 +219,3 @@ class Magicsig extends Memcached_DataObject
return base64_decode(strtr($input, '-_', '+/'));
}
}
-
-