phpseclib/phpseclib/Crypt/Common/Formats/Signature/Raw.php

67 lines
1.4 KiB
PHP
Raw Normal View History

2016-12-23 16:02:07 +00:00
<?php
/**
* Raw Signature Handler
*
* PHP version 5
*
* Handles signatures as arrays
*
* @category Crypt
* @package Common
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2016 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
2019-06-25 03:44:10 +00:00
namespace phpseclib\Crypt\Common\Formats\Signature;
2016-12-23 16:02:07 +00:00
use phpseclib\Math\BigInteger;
/**
* Raw Signature Handler
*
* @package Common
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
abstract class Raw
{
/**
* Loads a signature
*
* @access public
* @param array $sig
2017-08-03 07:16:16 +00:00
* @return array|bool
2016-12-23 16:02:07 +00:00
*/
public static function load($sig)
{
switch (true) {
case !is_array($sig):
case !isset($sig['r']) || !isset($sig['s']):
case !$sig['r'] instanceof BigInteger:
case !$sig['s'] instanceof BigInteger:
return false;
}
return [
'r' => $sig['r'],
's' => $sig['s']
2016-12-23 16:02:07 +00:00
];
}
/**
* Returns a signature in the appropriate format
*
* @access public
* @param \phpseclib\Math\BigInteger $r
* @param \phpseclib\Math\BigInteger $s
* @return string
*/
public static function save(BigInteger $r, BigInteger $s)
{
return compact('r', 's');
}
}