2016-12-23 16:02:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Raw Signature Handler
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* Handles signatures as arrays
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2022-06-04 15:31:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
namespace phpseclib3\Crypt\Common\Formats\Signature;
|
2016-12-23 16:02:07 +00:00
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\Math\BigInteger;
|
2016-12-23 16:02:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Raw Signature Handler
|
|
|
|
*
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
|
|
*/
|
|
|
|
abstract class Raw
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Loads a signature
|
|
|
|
*
|
2017-08-03 07:16:16 +00:00
|
|
|
* @return array|bool
|
2016-12-23 16:02:07 +00:00
|
|
|
*/
|
2022-06-04 15:31:21 +00:00
|
|
|
public static function load(array $sig)
|
2016-12-23 16:02:07 +00:00
|
|
|
{
|
|
|
|
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 [
|
2017-07-20 09:09:29 +00:00
|
|
|
'r' => $sig['r'],
|
|
|
|
's' => $sig['s']
|
2016-12-23 16:02:07 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a signature in the appropriate format
|
|
|
|
*/
|
2022-06-04 15:31:21 +00:00
|
|
|
public static function save(BigInteger $r, BigInteger $s): string
|
2016-12-23 16:02:07 +00:00
|
|
|
{
|
|
|
|
return compact('r', 's');
|
|
|
|
}
|
|
|
|
}
|