Skip to content

Commit

Permalink
Update CryptoProCli.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Zarubin authored Sep 13, 2019
1 parent 7e2f1fc commit e4e8104
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions CryptoProCli.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

namespace nikserg\cryptoprocli;

/**
* Class CryptoProCli
*
*
* Функции для работы с консольной утилитой КриптоПро
*
* @package nikserg\cryptoprocli
*/
class CryptoProCli {
class CryptoProCli
{
/**
* @var string Путь к исполняемому файлу Curl КриптоПро
*/
Expand All @@ -17,20 +19,21 @@ class CryptoProCli {

/**
* Подписать ранее неподписанный файл
*
*
* @param string $file
* @param string $thumbprint
* @param null $toFile
* @param null $toFile
* @throws \Exception
*/
public static function signFile($file, $thumbprint, $toFile = null)
{
$shellCommand = 'yes "o" 2>/dev/null | ' . self::$cryptcpExec .
$shellCommand = self::$cryptcpExec .
' -sign -thumbprint ' . $thumbprint . ' ' . $file . ' ' . $toFile;
$result = shell_exec($shellCommand);

if (strpos($result, "Signed message is created.") <= 0) {
throw new \Exception('В ответе Cryptcp не найдена строка Signed message is created: ' . $result . ' команда ' . $shellCommand);
if (strpos($result, "Signed message is created.") <= 0 && strpos($result,
"Подписанное сообщение успешно создано") <= 0) {
throw new \Exception('В ответе Cryptcp не найдена строка "Signed message is created" или "Подписанное сообщение успешно создано": ' . $result . ' команда ' . $shellCommand);
}
}

Expand All @@ -43,7 +46,7 @@ public static function signFile($file, $thumbprint, $toFile = null)
*/
public static function addSignToFile($file, $thumbprint)
{
$shellCommand = 'yes "o" | ' . self::$cryptcpExec .
$shellCommand = self::$cryptcpExec .
' -addsign -thumbprint ' . $thumbprint . ' ' . $file;
$result = shell_exec($shellCommand);

Expand Down

0 comments on commit e4e8104

Please sign in to comment.