From ac6fbfbc042b13d10645cc86654cf33116b7704a Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Tue, 8 Nov 2022 20:48:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CryptoPro.php | 61 +++++++++++------------------------------------ 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/src/CryptoPro.php b/src/CryptoPro.php index 6c3cab8..1013671 100755 --- a/src/CryptoPro.php +++ b/src/CryptoPro.php @@ -879,53 +879,7 @@ class CryptoPro throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при проверке подписи')); } - try - { - $cadesSigners = $cadesSignedData->get_Signers(); - $cadesSignersCount = (int) $cadesSigners->get_Count(); - } - catch (\Throwable $e) - { - throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка получения списка подписантов')); - } - - if (!$cadesSignersCount) - { - throw new \Exception('Нет доступных подписантов'); - } - - $signers = []; - - try - { - while ($cadesSignersCount) - { - $cadesSigner = $cadesSigners->get_Item($cadesSignersCount); - $cadesCertificate = $cadesSigner->get_Certificate(); - $certificate = new Certificate( - $cadesCertificate, - CertificateHelper::extractCommonName($cadesCertificate->get_SubjectName()), - $cadesCertificate->get_IssuerName(), - $cadesCertificate->get_SubjectName(), - $cadesCertificate->get_Thumbprint(), - $cadesCertificate->get_ValidFromDate(), - $cadesCertificate->get_ValidToDate() - ); - - $signers[] = [ - 'signing_time' => $cadesSigner->get_SigningTime(), - 'certificate' => $certificate - ]; - - $cadesSignersCount--; - } - } - catch (\Throwable $e) - { - throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при чтении информации о подписанте')); - } - - return $signers; + return static::getSigners($cadesSignedData); } /** @@ -973,6 +927,19 @@ class CryptoPro throw new \Exception(ErrorMessageHelper::getErrorMessage($e, 'Ошибка при проверке подписи')); } + return static::getSigners($cadesSignedData); + } + + /** + * Извлекает из подписи данные о подписантах + * + * @param \CPSignedData $cadesSignedData подписанные данные + * + * @throws \Exception + * @return array информация о подписантах + */ + protected static function getSigners(\CPSignedData $cadesSignedData) + { try { $cadesSigners = $cadesSignedData->get_Signers();