fix(formating)
This commit is contained in:
@@ -15,6 +15,7 @@ namespace Apoloz\AlfaBank\Services;
|
||||
// <BELIEF_STATE "The `SignerInterface` is imported to ensure that `OpenSslCmsSigner` adheres to a predefined contract for digital signing, promoting interoperability and testability within the SDK.">
|
||||
use Apoloz\AlfaBank\Contracts\SignerInterface;
|
||||
use Apoloz\AlfaBank\Exceptions\SignerException;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the OpenSSL-based CMS signer service.">
|
||||
@@ -34,12 +35,12 @@ class OpenSslCmsSigner implements SignerInterface
|
||||
public function sign(string $data): string
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(file_get_contents($this->privateKeyPath)); // assuming no passphrase for simplicity here
|
||||
if (!$privateKey) {
|
||||
if (! $privateKey) {
|
||||
throw new SignerException("Could not read private key for signing from {$this->privateKeyPath}.");
|
||||
}
|
||||
|
||||
$cert = openssl_x509_read(file_get_contents($this->certificatePath));
|
||||
if (!$cert) {
|
||||
if (! $cert) {
|
||||
throw new SignerException("Could not read certificate for signing from {$this->certificatePath}.");
|
||||
}
|
||||
|
||||
@@ -57,10 +58,14 @@ class OpenSslCmsSigner implements SignerInterface
|
||||
PKCS7_BINARY | PKCS7_DETACHED
|
||||
);
|
||||
|
||||
if (!$status) {
|
||||
if (file_exists($inFile)) unlink($inFile);
|
||||
if (file_exists($outFile)) unlink($outFile);
|
||||
throw new SignerException("Signing failed: " . openssl_error_string());
|
||||
if (! $status) {
|
||||
if (file_exists($inFile)) {
|
||||
unlink($inFile);
|
||||
}
|
||||
if (file_exists($outFile)) {
|
||||
unlink($outFile);
|
||||
}
|
||||
throw new SignerException('Signing failed: ' . openssl_error_string());
|
||||
}
|
||||
|
||||
$signedData = file_get_contents($outFile);
|
||||
@@ -69,7 +74,7 @@ class OpenSslCmsSigner implements SignerInterface
|
||||
|
||||
$parts = explode("\n\n", $signedData);
|
||||
$signature = end($parts);
|
||||
|
||||
|
||||
return str_replace(["\n", "\r"], '', $signature);
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
Reference in New Issue
Block a user