mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-19 11:45:10 +00:00
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
* @copyright 2015 Jim Wigginton
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace phpseclib3\Tests\Unit\Crypt\DSA;
|
|
|
|
use phpseclib3\Crypt\DSA;
|
|
use phpseclib3\Crypt\DSA\Parameters;
|
|
use phpseclib3\Crypt\DSA\PrivateKey;
|
|
use phpseclib3\Crypt\DSA\PublicKey;
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
|
|
|
/**
|
|
* @requires PHP 7.0
|
|
*/
|
|
class CreateKeyTest extends PhpseclibTestCase
|
|
{
|
|
public function testCreateParameters()
|
|
{
|
|
$dsa = DSA::createParameters();
|
|
$this->assertInstanceOf(Parameters::class, $dsa);
|
|
$this->assertMatchesRegularExpression('#BEGIN DSA PARAMETERS#', "$dsa");
|
|
|
|
try {
|
|
DSA::createParameters(100, 100);
|
|
} catch (\Exception $e) {
|
|
$this->assertInstanceOf(\Exception::class, $e);
|
|
}
|
|
|
|
$dsa = DSA::createParameters(512, 160);
|
|
$this->assertInstanceOf(Parameters::class, $dsa);
|
|
$this->assertMatchesRegularExpression('#BEGIN DSA PARAMETERS#', "$dsa");
|
|
|
|
return $dsa;
|
|
}
|
|
|
|
/**
|
|
* @depends testCreateParameters
|
|
*/
|
|
public function testCreateKey($params): void
|
|
{
|
|
$privatekey = DSA::createKey();
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
|
|
|
$privatekey = DSA::createKey($params);
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
|
|
|
$privatekey = DSA::createKey(512, 160);
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
|
}
|
|
}
|