db_objectified magic sig - for persistence of local keypairs

This commit is contained in:
James Walker 2010-02-22 22:55:26 -05:00
parent cb32b676fa
commit 74f5c1e169

View File

@ -29,21 +29,53 @@
require_once 'Crypt/RSA.php'; require_once 'Crypt/RSA.php';
class Magicsig class Magicsig extends Memcached_DataObject
{ {
public $__table = 'magicsig';
public $user_id;
public $keypair; public $keypair;
public $alg;
public function __construct($init = null) private $_rsa;
public /*static*/ function staticGet($k, $v=null)
{ {
if (is_null($init)) { return parent::staticGet(__CLASS__, $k, $v);
$this->generate();
} else {
$this->fromString($init);
}
} }
function table()
{
return array(
'user_id' => DB_DATAOBJECT_INT,
'keypair' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'alg' => DB_DATAOBJECT_STR
);
}
static function schemaDef()
{
return array(new ColumnDef('user_id', 'integer',
null, true, 'PRI'),
new ColumnDef('keypair', 'varchar',
255, false),
new ColumnDef('alg', 'varchar',
64, false));
}
function keys()
{
return array_keys($this->keyTypes());
}
function keyTypes()
{
return array('user_id' => 'K');
}
public function generate($key_length = 512) public function generate($key_length = 512)
{ {
$keypair = new Crypt_RSA_KeyPair($key_length); $keypair = new Crypt_RSA_KeyPair($key_length);