Skip to content

Commit

Permalink
Cleanup and minor changes/improvements
Browse files Browse the repository at this point in the history
Added individual addon exception.
Added support for signature properties in batch processes.
Removed $id$ placeholder in DocBlock comments.
Typos.
  • Loading branch information
JanSlabon committed Jun 1, 2015
1 parent a021b54 commit 3e2b473
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/demo-batch-on-demand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// load and register the autoload function
// require the autoload class from Composer
require_once('../vendor/autoload.php');

if (file_exists('credentials-on-demand.php')) {
Expand Down Expand Up @@ -72,7 +72,7 @@
),
);

// create document instance by the filenames
// create document instances by the filenames
$documents = array();
foreach ($files AS $file) {
$documents[] = SetaPDF_Core_Document::loadByFilename(
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-batch-ts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// load and register the autoload function
// require the autoload class from Composer
require_once('../vendor/autoload.php');

if (file_exists('credentials.php')) {
Expand Down Expand Up @@ -59,7 +59,7 @@
),
);

// create document instance by the filenames
// create document instances by the filenames
$documents = array();
foreach ($files AS $file) {
$documents[] = SetaPDF_Core_Document::loadByFilename(
Expand Down
9 changes: 6 additions & 3 deletions examples/demo-batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// load and register the autoload function
// require the autoload class from Composer
require_once('../vendor/autoload.php');

if (file_exists('credentials.php')) {
Expand Down Expand Up @@ -59,7 +59,7 @@
),
);

// create document instance by the filenames
// create document instances by the filenames
$documents = array();
foreach ($files AS $file) {
$documents[] = SetaPDF_Core_Document::loadByFilename(
Expand All @@ -75,7 +75,10 @@
// the signatures should include a timestamp, too
$batch->setAddTimestamp(true);
// sign the documents and add the revoke information to the DSS of the documents
$batch->sign($documents, true);
$batch->sign($documents, true, array(
SetaPDF_Signer::PROP_LOCATION => $_SERVER['SERVER_NAME'],
SetaPDF_Signer::PROP_REASON => 'Testing'
));

// get access to the last result object
$result = $batch->getLastResult();
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-on-demand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// load and register the autoload function
// require the autoload class from Composer
require_once('../vendor/autoload.php');

// prepare on-demand data
Expand Down Expand Up @@ -62,7 +62,7 @@
$signer->setAllowSignatureContentLengthChange(false);
$signer->setSignatureContentLength(32000);

// set some signature properies
// set some signature properties
$signer->setLocation($_SERVER['SERVER_NAME']);
$signer->setContactInfo('+01 2345 67890123');
$signer->setReason('testing...');
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-ts-ltv.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// load and register the autoload function
// require the autoload class from Composer
require_once('../vendor/autoload.php');

if (file_exists('credentials.php')) {
Expand Down Expand Up @@ -55,7 +55,7 @@
$signer->setSignatureContentLength(32000);
$signer->setSignatureFieldName($signatureFieldName);

// set some signature properies
// set some signature properties
$signer->setLocation($_SERVER['SERVER_NAME']);
$signer->setContactInfo('+01 2345 67890123');
$signer->setReason('testing...');
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-ts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// load and register the autoload function
// require the autoload class from Composer
require_once('../vendor/autoload.php');

if (file_exists('credentials.php')) {
Expand Down Expand Up @@ -49,7 +49,7 @@
$signer->setAllowSignatureContentLengthChange(false);
$signer->setSignatureContentLength(32000);

// set some signature properies
// set some signature properties
$signer->setLocation($_SERVER['SERVER_NAME']);
$signer->setContactInfo('+01 2345 67890123');
$signer->setReason('testing...');
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$signer->setAllowSignatureContentLengthChange(false);
$signer->setSignatureContentLength(32000);

// set some signature properies
// set some signature properties
$signer->setLocation($_SERVER['SERVER_NAME']);
$signer->setContactInfo('+01 2345 67890123');
$signer->setReason('Testing Swisscom AIS');
Expand Down
1 change: 0 additions & 1 deletion src/SetaPDF/Signer/SwisscomAIS/AbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @category SetaPDF
* @package SetaPDF_Signer
* @license http://www.apache.org/licenses/LICENSE-2.0
* @version $Id$
*/

/**
Expand Down
24 changes: 20 additions & 4 deletions src/SetaPDF/Signer/SwisscomAIS/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @category SetaPDF
* @package SetaPDF_Signer
* @license http://www.apache.org/licenses/LICENSE-2.0
* @version $Id$
*/

/**
Expand Down Expand Up @@ -89,7 +88,7 @@ public function getSignatureFieldName()
* @throws SetaPDF_Signer_Exception
* @throws SetaPDF_Signer_Exception_ContentLength
*/
public function sign(array $documents, $updateDss = false)
public function sign(array $documents, $updateDss = false, $signatureProperties = array())
{
$digestMethod = $this->_getDigestMethod();

Expand All @@ -100,6 +99,11 @@ public function sign(array $documents, $updateDss = false)
$signer = new SetaPDF_Signer($document);
$signer->setSignatureContentLength($this->getSignatureContentLength());
$signer->setSignatureFieldName($this->getSignatureFieldName());

foreach ($signatureProperties AS $name => $value) {
$signer->setSignatureProperty($name, $value);
}

$tmpDocument = $signer->preSign(new SetaPDF_Core_Writer_TempFile());

$data[$no] = array(
Expand Down Expand Up @@ -153,9 +157,15 @@ public function sign(array $documents, $updateDss = false)

$signResult = $this->_lastResult->SignResponse->Result;
if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') {
throw new SetaPDF_Signer_Exception(sprintf('Swisscom AIS webservice returned an error: %s',
$exception = new SetaPDF_Signer_SwisscomAIS_Exception(sprintf(
'Swisscom AIS webservice returned an error: %s',
$signResult->ResultMessage->_
));

$exception->setRequest($req);
$exception->setResult($this->_lastResult);

throw $exception;
}

$signatures = $this->_lastResult->SignResponse->SignatureObject->Other->SignatureObjects->ExtendedSignatureObject;
Expand Down Expand Up @@ -204,6 +214,7 @@ public function sign(array $documents, $updateDss = false)
* @throws SetaPDF_Core_Exception
* @throws SetaPDF_Signer_Exception
* @throws SetaPDF_Signer_Exception_ContentLength
* @throws SetaPDF_Signer_SwisscomAIS_Exception
*/
public function timestamp(array $documents, $updateDss = false)
{
Expand Down Expand Up @@ -267,9 +278,14 @@ public function timestamp(array $documents, $updateDss = false)

$signResult = $this->_lastResult->SignResponse->Result;
if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') {
throw new SetaPDF_Signer_Exception(sprintf('Swisscom AIS webservice returned an error: %s',
$exception = new SetaPDF_Signer_SwisscomAIS_Exception(sprintf('Swisscom AIS webservice returned an error: %s',
$signResult->ResultMessage->_
));

$exception->setRequest($req);
$exception->setResult($this->_lastResult);

throw $exception;
}

$timestamps = $this->_lastResult->SignResponse->SignatureObject->Other->SignatureObjects->ExtendedSignatureObject;
Expand Down
84 changes: 84 additions & 0 deletions src/SetaPDF/Signer/SwisscomAIS/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* This file is part of the demo pacakge of the SetaPDF-Signer Component
*
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @category SetaPDF
* @package SetaPDF_Signer
* @license http://www.apache.org/licenses/LICENSE-2.0
*/

/**
* Exception class for Swisscom AIS webservice.
*
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com)
* @category SetaPDF
* @package SetaPDF_Signer
* @license http://www.apache.org/licenses/LICENSE-2.0
*/
class SetaPDF_Signer_SwisscomAIS_Exception extends SetaPDF_Signer_Exception
{
/**
* @var stdClass|array
*/
protected $_request;

/**
* @var stdClass
*/
protected $_result;

/**
* Set the request data.
*
* @param $request
*/
public function setRequest($request)
{
$this->_request = $request;
}

/**
* Get the request data.
*
* @return array|stdClass
*/
public function getRequest()
{
return $this->_request;
}

/**
* Set the result of the webservice call.
*
* @param stdClass $result
*/
public function setResult($result)
{
$this->_result = $result;
}

/**
* Get the result of the webservice call.
* @return stdClass
*/
public function getResult()
{
require $this->_result;
}

/**
* Get the Mobile ID User Assistance URL (if available).
*
* @return null|string
*/
public function getMobileIdUserAssistanceUrl()
{
$lastResult = $this->getResult();
if (isset($lastResult->SignResponse->OptionalOutputs->MobileIDFault->Detail->UserAssistance->PortalUrl)) {
return $lastResult->SignResponse->OptionalOutputs->MobileIDFault->Detail->UserAssistance->PortalUrl;
}

return null;
}
}
17 changes: 13 additions & 4 deletions src/SetaPDF/Signer/SwisscomAIS/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @category SetaPDF
* @package SetaPDF_Signer
* @license http://www.apache.org/licenses/LICENSE-2.0
* @version $Id$
*/

/**
Expand Down Expand Up @@ -76,9 +75,14 @@ public function createSignature($tmpPath)

$signResult = $this->_lastResult->SignResponse->Result;
if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') {
throw new SetaPDF_Signer_Exception(sprintf('Swisscom AIS webservice returned an error: %s',
$exception = new SetaPDF_Signer_SwisscomAIS_Exception(sprintf('Swisscom AIS webservice returned an error: %s',
$signResult->ResultMessage->_
));

$exception->setRequest($req);
$exception->setResult($this->_lastResult);

throw $exception;
}

return $this->_lastResult->SignResponse->SignatureObject->Base64Signature->_;
Expand Down Expand Up @@ -129,10 +133,15 @@ public function createTimestamp($data)

$signResult = $this->_lastResult->SignResponse->Result;
if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') {

throw new SetaPDF_Signer_Exception(sprintf('Swisscom AIS webservice returned an error: %s',
$exception = new SetaPDF_Signer_SwisscomAIS_Exception(sprintf(
'Swisscom AIS webservice returned an error: %s',
$signResult->ResultMessage->_
));

$exception->setRequest($req);
$exception->setResult($this->_lastResult);

throw $exception;
}

return $this->_lastResult->SignResponse->SignatureObject->Timestamp->RFC3161TimeStampToken;
Expand Down

0 comments on commit 3e2b473

Please sign in to comment.