forked from apoloz/alfa-bank-sdk
feat: Add Laravel tinker examples and update nominal accounts functionality
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Services;
|
||||
// <SECTION name="module_imports" intent="Import necessary classes for the signer contract.">
|
||||
// <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
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(file_get_contents($this->privateKeyPath)); // assuming no passphrase for simplicity here
|
||||
if (!$privateKey) {
|
||||
throw new \Exception("Could not read private key for signing from {$this->privateKeyPath}.");
|
||||
throw new SignerException("Could not read private key for signing from {$this->privateKeyPath}.");
|
||||
}
|
||||
|
||||
$cert = openssl_x509_read(file_get_contents($this->certificatePath));
|
||||
if (!$cert) {
|
||||
throw new \Exception("Could not read certificate for signing from {$this->certificatePath}.");
|
||||
throw new SignerException("Could not read certificate for signing from {$this->certificatePath}.");
|
||||
}
|
||||
|
||||
$inFile = tempnam(sys_get_temp_dir(), 'alfa_in');
|
||||
@@ -57,9 +58,9 @@ class OpenSslCmsSigner implements SignerInterface
|
||||
);
|
||||
|
||||
if (!$status) {
|
||||
unlink($inFile);
|
||||
unlink($outFile);
|
||||
throw new \Exception("Signing failed: " . openssl_error_string());
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user