<commit_before><?php

namespace JWX\JWK\Parameter;


/**
 * Implements 'Curve' parameter.
 *
 * @link https://tools.ietf.org/html/rfc7518#section-6.2.1.1
 */
class CurveParameter extends RegisteredJWKParameter
{
	const CURVE_P256 = "P-256";
	const CURVE_P384 = "P-384";
	const CURVE_P521 = "P-521";
	
	/**
	 * Constructor
	 *
	 * @param string $curve Curve name
	 */
	public function __construct($curve) {
		parent::__construct(self::PARAM_CURVE, $curve);
	}
}<commit_msg>Add curve mappings<commit_after><?php

namespace JWX\JWK\Parameter;


/**
 * Implements 'Curve' parameter.
 *
 * @link https://tools.ietf.org/html/rfc7518#section-6.2.1.1
 */
class CurveParameter extends RegisteredJWKParameter
{
	const CURVE_P256 = "P-256";
	const CURVE_P384 = "P-384";
	const CURVE_P521 = "P-521";
	
	/**
	 * Mapping from curve OID to curve name.
	 *
	 * @internal
	 *
	 * @var array
	 */
	const MAP_OID_TO_CURVE = array(
		/* @formatter:off */
		"1.2.840.10045.3.1.7" => self::CURVE_P256,
		"1.3.132.0.34" => self::CURVE_P384,
		"1.3.132.0.35" => self::CURVE_P521
		/* @formatter:on */
	);
	
	/**
	 * Mapping from curve name to bit size.
	 *
	 * @internal
	 *
	 * @var array
	 */
	const MAP_CURVE_TO_SIZE = array(
		/* @formatter:off */
		self::CURVE_P256 => 256,
		self::CURVE_P384 => 384,
		self::CURVE_P521 => 521
		/* @formatter:on */
	);
	
	/**
	 * Constructor
	 *
	 * @param string $curve Curve name
	 */
	public function __construct($curve) {
		parent::__construct(self::PARAM_CURVE, $curve);
	}
	
	/**
	 * Initialize from curve OID.
	 *
	 * @param string $oid Object identifier in dotted format
	 * @throws \UnexpectedValueException If the curve is not supported
	 * @return self
	 */
	public static function fromOID($oid) {
		if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) {
			throw new \UnexpectedValueException("OID $oid not supported.");
		}
		$curve = self::MAP_OID_TO_CURVE[$oid];
		return new self($curve);
	}
	
	/**
	 * Get key size in bits for the curve.
	 *
	 * @throws \UnexpectedValueException
	 * @return int
	 */
	public function keySizeBits() {
		if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) {
			throw new \UnexpectedValueException(
				"Curve " . $this->_value . " not supported.");
		}
		return self::MAP_CURVE_TO_SIZE[$this->_value];
	}
	
	/**
	 * Get the curve OID by curve name.
	 *
	 * @param string $name Curve parameter name
	 * @throws \UnexpectedValueException If the curve is not supported
	 * @return string OID in dotted format
	 */
	public static function nameToOID($name) {
		static $reverseMap;
		if (!isset($reverseMap)) {
			$reverseMap = array_flip(self::MAP_OID_TO_CURVE);
		}
		if (!isset($reverseMap[$name])) {
			throw new \UnexpectedValueException("Curve $name not supported.");
		}
		return $reverseMap[$name];
	}
}
{'fraction_non_alphanumeric': 0.15035971223021583, 'fraction_numerical': 0.03884892086330935, 'mean_word_length': 3.536704730831974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '4878962', 'n_tokens_mistral': 1155, 'n_tokens_neox': 975, 'n_words': 222}