copenssl/src/OpenSSL.php
eater 2e64118f8c
Some checks failed
continuous-integration/drone/push Build is failing
Initial commit
2019-11-25 00:45:19 +01:00

53 lines
No EOL
1 KiB
PHP

<?php
namespace Cijber;
use Cijber\OpenSSL\Instance;
use FFI;
/**
* Class OpenSSL
* @package Cijber
*/
class OpenSSL
{
private static ?Instance $instance = null;
private static ?FFI $stdLib = null;
/**
* Get an OpenSSL instance which holds the FFI object,
* And initializes OpenSSL and frees when destructed
*
* @return Instance
*/
static function getInstance(): Instance
{
if (static::$instance === null) {
static::$instance = new Instance();
static::$instance->init();
}
return static::$instance;
}
public static function getFFI(): FFI
{
return static::getInstance()->getFFI();
}
public static function getStdLib(): FFI
{
if (static::$stdLib === null) {
static::$stdLib = FFI::cdef("void* malloc (size_t size);", "libc.so.6");
}
return static::$stdLib;
}
public static function malloc(int $size): FFI\CData
{
return static::getStdLib()->malloc($size);
}
}