mirror of
https://github.com/friendica/friendica
synced 2025-05-01 19:44:23 +02:00
Replace library/asn1.php with phpseclib
This commit is contained in:
parent
0af08ac1d4
commit
11ef3895f5
9 changed files with 197 additions and 455 deletions
|
@ -21,6 +21,8 @@
|
|||
*/
|
||||
namespace Friendica\Util;
|
||||
|
||||
use phpseclib\Crypt\RSA;
|
||||
use phpseclib\Math\BigInteger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CryptoTest extends TestCase
|
||||
|
@ -32,7 +34,7 @@ class CryptoTest extends TestCase
|
|||
private function assertRandomInt($min, $max)
|
||||
{
|
||||
global $phpMock;
|
||||
$phpMock['random_int'] = function($mMin, $mMax) use ($min, $max) {
|
||||
$phpMock['random_int'] = function ($mMin, $mMax) use ($min, $max) {
|
||||
$this->assertEquals($min, $mMin);
|
||||
$this->assertEquals($max, $mMax);
|
||||
return 1;
|
||||
|
@ -51,6 +53,50 @@ class CryptoTest extends TestCase
|
|||
$this->assertEquals(8, strlen($test));
|
||||
$this->assertEquals(11111111, $test);
|
||||
}
|
||||
|
||||
public function dataRsa()
|
||||
{
|
||||
return [
|
||||
'diaspora' => [
|
||||
'key' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-rsa-base64'),
|
||||
'expected' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-pem'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataRsa
|
||||
*/
|
||||
public function testPubRsaToMe(string $key, string $expected)
|
||||
{
|
||||
$this->assertEquals($expected, Crypto::rsaToPem(base64_decode($key)));
|
||||
}
|
||||
|
||||
|
||||
public function datePem()
|
||||
{
|
||||
return [
|
||||
'diaspora' => [
|
||||
'key' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-pem'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider datePem
|
||||
*/
|
||||
public function testPemToMe(string $key)
|
||||
{
|
||||
Crypto::pemToMe($key, $m, $e);
|
||||
|
||||
$expectedRSA = new RSA();
|
||||
$expectedRSA->loadKey([
|
||||
'e' => new BigInteger($e, 256),
|
||||
'n' => new BigInteger($m, 256)
|
||||
]);
|
||||
|
||||
$this->assertEquals($expectedRSA->getPublicKey(), $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue