-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from minvws/factory
Implemented factory
- Loading branch information
Showing
19 changed files
with
345 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace MinVWS\Crypto\Laravel; | ||
|
||
use MinVWS\Crypto\Laravel\Service\Cms; | ||
use MinVWS\Crypto\Laravel\Service\Signature; | ||
use MinVWS\Crypto\Laravel\Service\Sealbox\SealboxService; | ||
use MinVWS\Crypto\Laravel\Service\TempFileService; | ||
|
||
class Factory | ||
{ | ||
public static function createCmsCryptoService( | ||
array $encryptionCertPaths = [], | ||
?string $decryptionCertPath = null, | ||
?string $decryptionKeyPath = null, | ||
bool $forceProcessSpawn = false | ||
): CmsCryptoInterface { | ||
if (function_exists('openssl_cms_encrypt') && !$forceProcessSpawn) { | ||
$tmpFile = new TempFileService(); | ||
|
||
return new Cms\NativeService( | ||
$encryptionCertPaths, | ||
$decryptionCertPath, | ||
$decryptionKeyPath, | ||
$tmpFile | ||
); | ||
} | ||
|
||
return new Cms\ProcessSpawnService( | ||
$encryptionCertPaths, | ||
$decryptionCertPath, | ||
$decryptionKeyPath, | ||
); | ||
} | ||
|
||
public static function createSealboxCryptoService( | ||
?string $privKey = null, | ||
?string $recipientPubKey = null | ||
): SealboxCryptoInterface { | ||
return new SealboxService($privKey, $recipientPubKey); | ||
} | ||
|
||
public static function createSignatureCryptoService( | ||
?string $certificatePath = null, | ||
?string $certificateKeyPath = null, | ||
?string $certificateKeyPass = null, | ||
?string $certificateChain = null, | ||
bool $forceProcessSpawn = false | ||
): SignatureCryptoInterface { | ||
$args = [ | ||
$certificatePath, | ||
$certificateKeyPath, | ||
$certificateKeyPass, | ||
$certificateChain, | ||
app(TempFileInterface::class), | ||
]; | ||
|
||
if (function_exists('openssl_cms_sign') && !$forceProcessSpawn) { | ||
return new Signature\NativeService(...$args); | ||
} | ||
|
||
return new Signature\ProcessSpawnService(...$args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.