/** * CryptoKey constructor. * * @param resource $resource The OpenSSL key resource. * @param array $config The OpenSSL config array to use. * @throws InvalidArgumentException when the given $resource is not of type 'OpenSSL key resource'. * @since 0.3 */ public function __construct($resource, array $config = self::DEFAULT_CONFIG) { OpenSSL::isAvailable(true); if (!is_resource($resource)) { // @codeCoverageIgnoreStart throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be a resource, %s given.', __FUNCTION__, gettype($resource))); // @codeCoverageIgnoreEnd } if (($rtype = get_resource_type($resource)) !== 'OpenSSL key') { // @codeCoverageIgnoreStart throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an \'OpenSSL key\' resource, \'%s\' resource given.', __FUNCTION__, $rtype)); // @codeCoverageIgnoreEnd } $this->resource = $resource; $this->config = $config; $this->loadDetails(true); }
/** * Gets all the supported cipher methods. * * @return array Returns a numerically indexed array containing the list of supported cipher methods. * @since 0.1 */ public static function allAvailable() : array { OpenSSL::isAvailable(true); if (self::$availableMethods === null) { $methods = array_unique(array_map('strtoupper', openssl_get_cipher_methods(true))); self::$availableMethods = array_unique(self::trimCipherMode($methods)); } return self::$availableMethods; }