Start PKCS7 type specific classes
continuous-integration/drone/push Build is passing Details

master
eater 5 years ago
parent d0e4d03e96
commit f884a650f4
Signed by: eater
GPG Key ID: AD2560A0F84F0759

@ -30,12 +30,13 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner
return $this->ffi->OBJ_obj2nid($this->cObj->type); return $this->ffi->OBJ_obj2nid($this->cObj->type);
} }
public function verify(string $plain): bool public function toSigned(): PKCS7\Signed
{ {
$type = $this->getType(); if ($this->getType() !== self::NID_SIGNED) {
if (!in_array($type, [PKCS7::NID_DIGEST, self::NID_SIGNED, self::NID_SIGNED_AND_ENVELOPED])) { throw new \RuntimeException("This PKCS7 isn't of type signed");
throw new \RuntimeException("Can only verify signed or digested data");
} }
return new PKCS7\Signed($this);
} }
/** /**
@ -59,6 +60,7 @@ class PKCS7 extends OpenSSL\C\CBackedObjectWithOwner
$val = FFI::string($buf, $len); $val = FFI::string($buf, $len);
// Free buffer via CRYPTO_free as OpenSSL malloc'd it // Free buffer via CRYPTO_free as OpenSSL malloc'd it
$this->ffi->CRYPTO_free($buf); $this->ffi->CRYPTO_free($buf);
return $val; return $val;
} }

@ -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;
}
}

@ -0,0 +1,14 @@
<?php
namespace Cijber\OpenSSL\PKCS7;
class Signed
{
use Helpers;
function getSigners() {
}
}
Loading…
Cancel
Save