Skip to content

Commit

Permalink
Merge pull request #31 from erikn69/patch-4
Browse files Browse the repository at this point in the history
Added `get_signature_count` method
  • Loading branch information
dealfonso authored Oct 26, 2022
2 parents c19e20a + 4c4064c commit 7782f7f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/PDFDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,4 +1041,53 @@ public function get_object_tree() {

return $objects;
}


/**
* Retrieve the signatures in the document
* @return array of signatures in the original document
*/
public function get_signatures() {

// Prepare the return value
$signatures = [];

foreach ($this->_xref_table as $oid => $offset) {
if ($offset === null) continue;

$o = $this->get_object($oid);
if ($o === false) continue;

$o_value = $o->get_value()->val();
if (! is_array($o_value) || ! isset($o_value['Type'])) continue;
if ($o_value['Type']->val() != 'Sig') continue;

$signature = ['content' => $o_value['Contents']->val()];

try {
$cert=[];

openssl_pkcs7_read(
"-----BEGIN CERTIFICATE-----\n"
. chunk_split(base64_encode(hex2bin($signature['content'])), 64, "\n")
. "-----END CERTIFICATE-----\n",
$cert
);

$signature += openssl_x509_parse($cert[0]);
} catch (\Exception $e) {}

$signatures[] = $signature;
}

return $signatures;
}

/**
* Retrieve the number of signatures in the document
* @return int signatures number in the original document
*/
public function get_signature_count() {
return count($this->get_signatures());
}
}

0 comments on commit 7782f7f

Please sign in to comment.