2016-12-23 16:02:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
|
|
* @copyright 2015 Jim Wigginton
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\Crypt\DSA;
|
|
|
|
use phpseclib3\Crypt\DSA\Parameters;
|
|
|
|
use phpseclib3\Crypt\DSA\PublicKey;
|
|
|
|
use phpseclib3\Crypt\DSA\PrivateKey;
|
2016-12-23 16:02:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @requires PHP 7.0
|
|
|
|
*/
|
2021-04-17 11:53:11 +00:00
|
|
|
class Unit_Crypt_DSA_CreateKeyTestDSA extends PhpseclibTestCase
|
2016-12-23 16:02:07 +00:00
|
|
|
{
|
|
|
|
public function testCreateParameters()
|
|
|
|
{
|
|
|
|
$dsa = DSA::createParameters();
|
2019-05-19 20:35:29 +00:00
|
|
|
$this->assertInstanceOf(Parameters::class, $dsa);
|
2016-12-23 16:02:07 +00:00
|
|
|
$this->assertRegexp('#BEGIN DSA PARAMETERS#', "$dsa");
|
|
|
|
|
2019-05-19 20:35:29 +00:00
|
|
|
try {
|
|
|
|
$dsa = DSA::createParameters(100, 100);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->assertInstanceOf(Exception::class, $e);
|
|
|
|
}
|
2016-12-23 16:02:07 +00:00
|
|
|
|
|
|
|
$dsa = DSA::createParameters(512, 160);
|
2019-05-19 20:35:29 +00:00
|
|
|
$this->assertInstanceOf(Parameters::class, $dsa);
|
2016-12-23 16:02:07 +00:00
|
|
|
$this->assertRegexp('#BEGIN DSA PARAMETERS#', "$dsa");
|
|
|
|
|
|
|
|
return $dsa;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateParameters
|
|
|
|
*/
|
|
|
|
public function testCreateKey($params)
|
|
|
|
{
|
2019-05-19 20:35:29 +00:00
|
|
|
$privatekey = DSA::createKey();
|
|
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
2016-12-23 16:02:07 +00:00
|
|
|
|
2019-05-19 20:35:29 +00:00
|
|
|
$privatekey = DSA::createKey($params);
|
|
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
2016-12-23 16:02:07 +00:00
|
|
|
|
2019-05-19 20:35:29 +00:00
|
|
|
$privatekey = DSA::createKey(512, 160);
|
|
|
|
$this->assertInstanceOf(PrivateKey::class, $privatekey);
|
|
|
|
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
|
2016-12-23 16:02:07 +00:00
|
|
|
}
|
|
|
|
}
|