Start PKCS7 type specific classes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d0e4d03e96
commit
f884a650f4
3 changed files with 50 additions and 4 deletions
|
@ -30,12 +30,13 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner
|
|||
return $this->ffi->OBJ_obj2nid($this->cObj->type);
|
||||
}
|
||||
|
||||
public function verify(string $plain): bool
|
||||
public function toSigned(): PKCS7\Signed
|
||||
{
|
||||
$type = $this->getType();
|
||||
if (!in_array($type, [PKCS7::NID_DIGEST, self::NID_SIGNED, self::NID_SIGNED_AND_ENVELOPED])) {
|
||||
throw new \RuntimeException("Can only verify signed or digested data");
|
||||
if ($this->getType() !== self::NID_SIGNED) {
|
||||
throw new \RuntimeException("This PKCS7 isn't of type signed");
|
||||
}
|
||||
|
||||
return new PKCS7\Signed($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,6 +60,7 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner
|
|||
$val = FFI::string($buf, $len);
|
||||
// Free buffer via CRYPTO_free as OpenSSL malloc'd it
|
||||
$this->ffi->CRYPTO_free($buf);
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
|
30
src/OpenSSL/PKCS7/Helpers.php
Normal file
30
src/OpenSSL/PKCS7/Helpers.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Cijber\OpenSSL\PKCS7;
|
||||
|
||||
|
||||
use Cijber\OpenSSL\PKCS7;
|
||||
|
||||
trait Helpers
|
||||
{
|
||||
protected PKCS7 $pkcs7;
|
||||
|
||||
function toDER(): string
|
||||
{
|
||||
return $this->pkcs7->toDER();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PKCS7
|
||||
*/
|
||||
public function getPkcs7(): PKCS7
|
||||
{
|
||||
return $this->pkcs7;
|
||||
}
|
||||
|
||||
public function __construct(PKCS7 $pkcs7)
|
||||
{
|
||||
$this->pkcs7 = $pkcs7;
|
||||
}
|
||||
}
|
14
src/OpenSSL/PKCS7/Signed.php
Normal file
14
src/OpenSSL/PKCS7/Signed.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Cijber\OpenSSL\PKCS7;
|
||||
|
||||
|
||||
class Signed
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
function getSigners() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue