2016-12-23 17:02:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
|
|
* @copyright 2015 Jim Wigginton
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2022-06-04 17:31:21 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-02-23 03:48:51 +01:00
|
|
|
namespace phpseclib3\Tests\Unit\Crypt\DSA;
|
|
|
|
|
2019-11-07 06:41:40 +01:00
|
|
|
use phpseclib3\Crypt\DSA;
|
|
|
|
use phpseclib3\Crypt\DSA\Parameters;
|
|
|
|
use phpseclib3\Crypt\DSA\PrivateKey;
|
2022-01-30 16:34:42 +01:00
|
|
|
use phpseclib3\Crypt\DSA\PublicKey;
|
2022-02-23 03:48:51 +01:00
|
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
2016-12-23 17:02:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @requires PHP 7.0
|
|
|
|
*/
|
2022-02-23 03:48:51 +01:00
|
|
|
class CreateKeyTest extends PhpseclibTestCase
|
2016-12-23 17:02:07 +01:00
|
|
|
{
|
|
|
|
public function testCreateParameters()
|
|
|
|
{
|
|
|
|
$dsa = DSA::createParameters();
|
2019-05-19 22:35:29 +02:00
|
|
|
$this->assertInstanceOf(Parameters::class, $dsa);
|
2022-03-09 01:59:30 +01:00
|
|
|
$this->assertMatchesRegularExpression('#BEGIN DSA PARAMETERS#', "$dsa");
|
2016-12-23 17:02:07 +01:00
|
|
|
|
2019-05-19 22:35:29 +02:00
|
|
|
try {
|
2022-03-09 01:59:30 +01:00
|
|
|
DSA::createParameters(100, 100);
|
2022-02-23 03:48:51 +01:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->assertInstanceOf(\Exception::class, $e);
|
2019-05-19 22:35:29 +02:00
|
|
|
}
|
2016-12-23 17:02:07 +01:00
|
|
|
|
|
|
|
$dsa = DSA::createParameters(512, 160);
|
2019-05-19 22:35:29 +02:00
|
|
|
$this->assertInstanceOf(Parameters::class, $dsa);
|
2022-03-09 01:59:30 +01:00
|
|
|
$this->assertMatchesRegularExpression('#BEGIN DSA PARAMETERS#', "$dsa");
|
2016-12-23 17:02:07 +01:00
|
|
|
|
|
|
|
return $dsa;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateParameters
|
|
|
|
*/
|
2022-06-04 17:31:21 +02:00
|
|
|
public function testCreateKey($params): void
|
2016-12-23 17:02:07 +01:00
|
|
|
{
|
2019-05-19 22:35:29 +02:00
|
|
|
$privatekey = DSA::createKey();
|
|
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
2016-12-23 17:02:07 +01:00
|
|
|
|
2019-05-19 22:35:29 +02:00
|
|
|
$privatekey = DSA::createKey($params);
|
|
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
2016-12-23 17:02:07 +01:00
|
|
|
|
2019-05-19 22:35:29 +02:00
|
|
|
$privatekey = DSA::createKey(512, 160);
|
|
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
2016-12-23 17:02:07 +01:00
|
|
|
}
|
|
|
|
}
|