change function name
This commit is contained in:
parent
59e34122b7
commit
21edb98a32
@ -33,20 +33,20 @@ class Magicsig extends Memcached_DataObject
|
|||||||
{
|
{
|
||||||
|
|
||||||
const PUBLICKEYREL = 'magic-public-key';
|
const PUBLICKEYREL = 'magic-public-key';
|
||||||
|
|
||||||
public $__table = 'magicsig';
|
public $__table = 'magicsig';
|
||||||
|
|
||||||
public $user_id;
|
public $user_id;
|
||||||
public $keypair;
|
public $keypair;
|
||||||
public $alg;
|
public $alg;
|
||||||
|
|
||||||
private $_rsa;
|
private $_rsa;
|
||||||
|
|
||||||
public function __construct($alg = 'RSA-SHA256')
|
public function __construct($alg = 'RSA-SHA256')
|
||||||
{
|
{
|
||||||
$this->alg = $alg;
|
$this->alg = $alg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public /*static*/ function staticGet($k, $v=null)
|
public /*static*/ function staticGet($k, $v=null)
|
||||||
{
|
{
|
||||||
$obj = parent::staticGet(__CLASS__, $k, $v);
|
$obj = parent::staticGet(__CLASS__, $k, $v);
|
||||||
@ -57,7 +57,6 @@ class Magicsig extends Memcached_DataObject
|
|||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function table()
|
function table()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@ -77,7 +76,6 @@ class Magicsig extends Memcached_DataObject
|
|||||||
64, false));
|
64, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function keys()
|
function keys()
|
||||||
{
|
{
|
||||||
return array_keys($this->keyTypes());
|
return array_keys($this->keyTypes());
|
||||||
@ -114,7 +112,6 @@ class Magicsig extends Memcached_DataObject
|
|||||||
$this->insert();
|
$this->insert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function toString($full_pair = true)
|
public function toString($full_pair = true)
|
||||||
{
|
{
|
||||||
$public_key = $this->_rsa->_public_key;
|
$public_key = $this->_rsa->_public_key;
|
||||||
@ -127,15 +124,15 @@ class Magicsig extends Memcached_DataObject
|
|||||||
$private_exp = '.' . base64_url_encode($private_key->getExponent());
|
$private_exp = '.' . base64_url_encode($private_key->getExponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'RSA.' . $mod . '.' . $exp . $private_exp;
|
return 'RSA.' . $mod . '.' . $exp . $private_exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromString($text)
|
public static function fromString($text)
|
||||||
{
|
{
|
||||||
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
|
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
|
||||||
|
|
||||||
$magic_sig = new Magicsig();
|
$magic_sig = new Magicsig();
|
||||||
|
|
||||||
// remove whitespace
|
// remove whitespace
|
||||||
$text = preg_replace('/\s+/', '', $text);
|
$text = preg_replace('/\s+/', '', $text);
|
||||||
|
|
||||||
@ -143,7 +140,7 @@ class Magicsig extends Memcached_DataObject
|
|||||||
if (!preg_match('/RSA\.([^\.]+)\.([^\.]+)(.([^\.]+))?/', $text, $matches)) {
|
if (!preg_match('/RSA\.([^\.]+)\.([^\.]+)(.([^\.]+))?/', $text, $matches)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mod = base64_url_decode($matches[1]);
|
$mod = base64_url_decode($matches[1]);
|
||||||
$exp = base64_url_decode($matches[2]);
|
$exp = base64_url_decode($matches[2]);
|
||||||
if ($matches[4]) {
|
if ($matches[4]) {
|
||||||
@ -185,10 +182,10 @@ class Magicsig extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sign($bytes)
|
public function sign($bytes)
|
||||||
{
|
{
|
||||||
$sig = $this->_rsa->createSign($bytes, null, 'sha256');
|
$sig = $this->_rsa->createSign($bytes, null, 'magicsig_sha256');
|
||||||
if ($this->_rsa->isError()) {
|
if ($this->_rsa->isError()) {
|
||||||
$error = $this->_rsa->getLastError();
|
$error = $this->_rsa->getLastError();
|
||||||
common_log(LOG_DEBUG, 'RSA Error: '. $error->getMessage());
|
common_log(LOG_DEBUG, 'RSA Error: '. $error->getMessage());
|
||||||
@ -200,7 +197,7 @@ class Magicsig extends Memcached_DataObject
|
|||||||
|
|
||||||
public function verify($signed_bytes, $signature)
|
public function verify($signed_bytes, $signature)
|
||||||
{
|
{
|
||||||
$result = $this->_rsa->validateSign($signed_bytes, $signature, null, 'sha256');
|
$result = $this->_rsa->validateSign($signed_bytes, $signature, null, 'magicsig_sha256');
|
||||||
if ($this->_rsa->isError()) {
|
if ($this->_rsa->isError()) {
|
||||||
$error = $this->keypair->getLastError();
|
$error = $this->keypair->getLastError();
|
||||||
common_log(LOG_DEBUG, 'RSA Error: '. $error->getMessage());
|
common_log(LOG_DEBUG, 'RSA Error: '. $error->getMessage());
|
||||||
@ -208,12 +205,12 @@ class Magicsig extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define a sha256 function for hashing
|
// Define a sha256 function for hashing
|
||||||
// (Crypt_RSA should really be updated to use hash() )
|
// (Crypt_RSA should really be updated to use hash() )
|
||||||
function sha256($bytes)
|
function magicsig_sha256($bytes)
|
||||||
{
|
{
|
||||||
return hash('sha256', $bytes);
|
return hash('sha256', $bytes);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user