<commit_before><?php

namespace JWX\JWS\Algorithm;

use JWX\JWS\SignatureAlgorithm;
use JWX\JWK\RSA\RSAPublicKeyJWK;
use JWX\JWK\RSA\RSAPrivateKeyJWK;


/**
 * Base class for algorithms implementing signature with PKCS #1.
 */
abstract class RSAPKCS1Algorithm implements SignatureAlgorithm
{
	/**
	 * Public key
	 *
	 * @var RSAPublicKeyJWK $_publicKey
	 */
	protected $_publicKey;
	
	/**
	 * Private key
	 *
	 * @var RSAPrivateKeyJWK|null $_privateKey
	 */
	protected $_privateKey;
	
	/**
	 * Get message digest method name supported by openssl
	 *
	 * @return string
	 */
	abstract protected function _mdMethod();
	
	/**
	 * Constructor
	 *
	 * Use <b>fromPublicKey</b> or <b>fromPrivateKey</b>
	 * static initializers instead.
	 */
	protected function __construct() {}
	
	/**
	 * Initialize from public key
	 *
	 * @param RSAPublicKeyJWK $jwk
	 * @return self
	 */
	public static function fromPublicKey(RSAPublicKeyJWK $jwk) {
		$obj = new static();
		$obj->_publicKey = $jwk;
		return $obj;
	}
	
	/**
	 * Initialize from private key
	 *
	 * @param RSAPrivateKeyJWK $jwk
	 * @return self
	 */
	public static function fromPrivateKey(RSAPrivateKeyJWK $jwk) {
		$obj = new static();
		$obj->_publicKey = $jwk->publicKey();
		$obj->_privateKey = $jwk;
		return $obj;
	}
	
	/**
	 * NOTE: OpenSSL uses PKCS #1 v1.5 padding by default, so
	 * no explicit padding is required by sign and verify operations.<commit_msg>Change keys to be passed via constructor<commit_after><?php

namespace JWX\JWS\Algorithm;

use JWX\JWS\SignatureAlgorithm;
use JWX\JWK\RSA\RSAPublicKeyJWK;
use JWX\JWK\RSA\RSAPrivateKeyJWK;


/**
 * Base class for algorithms implementing signature with PKCS #1.
 */
abstract class RSAPKCS1Algorithm implements SignatureAlgorithm
{
	/**
	 * Public key
	 *
	 * @var RSAPublicKeyJWK $_publicKey
	 */
	protected $_publicKey;
	
	/**
	 * Private key
	 *
	 * @var RSAPrivateKeyJWK|null $_privateKey
	 */
	protected $_privateKey;
	
	/**
	 * Get message digest method name supported by openssl
	 *
	 * @return string
	 */
	abstract protected function _mdMethod();
	
	/**
	 * Constructor
	 *
	 * Use <b>fromPublicKey</b> or <b>fromPrivateKey</b>
	 * static initializer instead!
	 *
	 * @param RSAPublicKeyJWK $pub_key
	 * @param RSAPrivateKeyJWK $priv_key
	 */
	protected function __construct(RSAPublicKeyJWK $pub_key, 
		RSAPrivateKeyJWK $priv_key = null) {
		$this->_publicKey = $pub_key;
		$this->_privateKey = $priv_key;
	}
	
	/**
	 * Initialize from public key
	 *
	 * @param RSAPublicKeyJWK $jwk
	 * @return self
	 */
	public static function fromPublicKey(RSAPublicKeyJWK $jwk) {
		return new static($jwk);
	}
	
	/**
	 * Initialize from private key
	 *
	 * @param RSAPrivateKeyJWK $jwk
	 * @return self
	 */
	public static function fromPrivateKey(RSAPrivateKeyJWK $jwk) {
		return new static($jwk->publicKey(), $jwk);
	}
	
	/**
	 * NOTE: OpenSSL uses PKCS #1 v1.5 padding by default, so
	 * no explicit padding is required by sign and verify operations.
{'fraction_non_alphanumeric': 0.11444969615124916, 'fraction_numerical': 0.00337609723160027, 'mean_word_length': 3.586687306501548, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, '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': '3006692', 'n_tokens_mistral': 1121, 'n_tokens_neox': 966, 'n_words': 262}