Skip to content

Commit

Permalink
Fix decode return type (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandocharles authored Nov 9, 2021
1 parent fca0fef commit 1e0d148
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/CER.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $cerFile)
);
}

public function decode(): string
public function decode(): ?string
{
$prefix = "-----BEGIN CERTIFICATE-----\n";
$suffix = "-----END CERTIFICATE-----\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class Certificate
{
use HasFiles;

abstract public function decode(): string;
abstract public function decode(): ?string;

public function save(string $directory, string $filename)
{
Expand Down
2 changes: 1 addition & 1 deletion src/KEY.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $keyFile, string $password)
$this->password = $password;
}

public function decode(): string
public function decode(): ?string
{
return shell_exec(sprintf(
"openssl pkcs8 -inform DER -in %s -passin pass:%s",
Expand Down
14 changes: 13 additions & 1 deletion tests/KEYTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

class KEYTest extends TestCase
{
public function testConvertKeyToPem()
/** @test */
public function it_should_decode_the_given_key()
{
$keyFileName = './tests/files/CSD01_AAA010101AAA.key';
$password = '12345678a';
Expand All @@ -28,4 +29,15 @@ public function testConvertKeyToPem()
file_get_contents("{$keyFileName}.pem")
);
}

/** @test */
public function it_should_return_null_when_the_password_doesnt_decode_the_key()
{
$keyFileName = './tests/files/CSD01_AAA010101AAA.key';
$password = '87654321a';

$strategy = new KEY($keyFileName, $password);

$this->assertEquals($strategy->decode(), null);
}
}

0 comments on commit 1e0d148

Please sign in to comment.