<commit_before><?php

namespace JWX\JWK\Symmetric;

use JWX\JWK\JWK;
use JWX\JWK\Parameter\JWKParameter;
use JWX\JWK\Parameter\KeyTypeParameter;
use JWX\JWK\Parameter\KeyValueParameter;
use JWX\JWK\Parameter\RegisteredJWKParameter;
use JWX\Util\Base64;


/**
 * JWK containing a symmetric key.
 *
 * @link http://tools.ietf.org/html/rfc7518#section-6.4
 */
class SymmetricKeyJWK extends JWK
{
	/**
	 * Parameter names managed by this class.
	 *
	 * @internal
	 *
	 * @var string[]
	 */
	const MANAGED_PARAMS = array(
		/* @formatter:off */
		RegisteredJWKParameter::PARAM_KEY_TYPE, 
		RegisteredJWKParameter::PARAM_KEY_VALUE
		/* @formatter:on */
	);
	
	/**
	 * Constructor
	 *
	 * @param JWKParameter ...$params
	 * @throws \UnexpectedValueException If missing required parameter
	 */
	public function __construct(JWKParameter ...$params) {
		parent::__construct(...$params);
		foreach (self::MANAGED_PARAMS as $name) {
			if (!$this->has($name)) {
				throw new \UnexpectedValueException("Missing '$name' parameter.");
			}
		}
		if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_OCT) {
			throw new \UnexpectedValueException("Invalid key type.");
		}
	}
	
	/**
	 * Initialize from a key string.
	 *
	 * @param string $key Symmetric key
	 * @param JWKParameter ...$params Optional additional parameters
	 * @return self
	 */
	public static function fromKey($key, JWKParameter ...$params) {
		$params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT);
		$params[] = new KeyValueParameter($key);
		return new self(...$params);
	}
	
	/**
	 * Get the symmetric key.
	 *
	 * @return string
	 */
	public function key() {
		return Base64::urlDecode($this->keyValueParameter()->value());
	}
}<commit_msg>Fix fromKey method<commit_after><?php

namespace JWX\JWK\Symmetric;

use JWX\JWK\JWK;
use JWX\JWK\Parameter\JWKParameter;
use JWX\JWK\Parameter\KeyTypeParameter;
use JWX\JWK\Parameter\KeyValueParameter;
use JWX\JWK\Parameter\RegisteredJWKParameter;
use JWX\Util\Base64;


/**
 * JWK containing a symmetric key.
 *
 * @link http://tools.ietf.org/html/rfc7518#section-6.4
 */
class SymmetricKeyJWK extends JWK
{
	/**
	 * Parameter names managed by this class.
	 *
	 * @internal
	 *
	 * @var string[]
	 */
	const MANAGED_PARAMS = array(
		/* @formatter:off */
		RegisteredJWKParameter::PARAM_KEY_TYPE, 
		RegisteredJWKParameter::PARAM_KEY_VALUE
		/* @formatter:on */
	);
	
	/**
	 * Constructor
	 *
	 * @param JWKParameter ...$params
	 * @throws \UnexpectedValueException If missing required parameter
	 */
	public function __construct(JWKParameter ...$params) {
		parent::__construct(...$params);
		foreach (self::MANAGED_PARAMS as $name) {
			if (!$this->has($name)) {
				throw new \UnexpectedValueException("Missing '$name' parameter.");
			}
		}
		if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_OCT) {
			throw new \UnexpectedValueException("Invalid key type.");
		}
	}
	
	/**
	 * Initialize from a key string.
	 *
	 * @param string $key Symmetric key
	 * @param JWKParameter ...$params Optional additional parameters
	 * @return self
	 */
	public static function fromKey($key, JWKParameter ...$params) {
		$params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT);
		$params[] = KeyValueParameter::fromString($key);
		return new self(...$params);
	}
	
	/**
	 * Get the symmetric key.
	 *
	 * @return string
	 */
	public function key() {
		return Base64::urlDecode($this->keyValueParameter()->value());
	}
}
{'fraction_non_alphanumeric': 0.14804063860667635, 'fraction_numerical': 0.005805515239477504, 'mean_word_length': 3.8810198300283285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5819014', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1112, 'n_words': 241}