<commit_before><?php

/*
 * This file is part of the WebPush library.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Minishlink\WebPush;

use Base64Url\Base64Url;
use Jose\Factory\JWKFactory;
use Jose\Factory\JWSFactory;
use Mdanter\Ecc\EccFactory;
use Mdanter\Ecc\Serializer\PrivateKey\DerPrivateKeySerializer;
use Mdanter\Ecc\Serializer\PrivateKey\PemPrivateKeySerializer;

class VAPID
{
    /**
     * @param array $vapid
     *
     * @return array
     *
     * @throws \ErrorException
     */
    public static function validate(array $vapid)
    {
        if (!array_key_exists('subject', $vapid)) {
            throw new \ErrorException('[VAPID] You must provide a subject that is either a mailto: or a URL.');
        }

        if (!array_key_exists('publicKey', $vapid)) {
            throw new \ErrorException('[VAPID] You must provide a public key.');
        }

        $publicKey = Base64Url::decode($vapid['publicKey']);

        if (Utils::safe_strlen($publicKey) !== 65) {
            throw new \ErrorException('[VAPID] Public key should be 65 bytes long when decoded.');
        }

        if (!array_key_exists('privateKey', $vapid)) {
            throw new \ErrorException('[VAPID] You must provide a private key.');
        }

        $privateKey = Base64Url::decode($vapid['privateKey']);

        if (Utils::safe_strlen($privateKey) !== 32) {
            throw new \ErrorException('[VAPID] Private key should be 32 bytes long when decoded.');
        }

        return array(
            'subject' => $vapid['subject'],
            'publicKey' => $publicKey,
            'privateKey' => $privateKey,
        );
    }

    /**
     * This method takes the required VAPID parameters and returns the required
     * header to be added to a Web Push Protocol Request.
     *
     * @param string $audience   This must be the origin of the push service
     * @param string $subject    This should be a URL or a 'mailto:' email address
     * @param string $publicKey  The decoded VAPID public key
     * @param string $privateKey The decoded VAPID private key
     * @param int    $expiration The expiration of the VAPID JWT. (UNIX timestamp)
     *
     * @return array Returns an array with the 'Authorization' and 'Crypto-Key' values to be used as headers
     */
    public static function getVapidHeaders($audience, $subject, $publicKey, $privateKey, $expiration = null)<commit_msg>fix merge<commit_after><?php

/*
 * This file is part of the WebPush library.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Minishlink\WebPush;

use Base64Url\Base64Url;
use Jose\Factory\JWKFactory;
use Jose\Factory\JWSFactory;
use Mdanter\Ecc\EccFactory;
use Mdanter\Ecc\Serializer\PrivateKey\DerPrivateKeySerializer;
use Mdanter\Ecc\Serializer\PrivateKey\PemPrivateKeySerializer;

class VAPID
{
    /**
     * @param array $vapid
     *
     * @return array
     *
     * @throws \ErrorException
     */
    public static function validate(array $vapid)
    {
        if (!array_key_exists('subject', $vapid)) {
            throw new \ErrorException('[VAPID] You must provide a subject that is either a mailto: or a URL.');
        }

        if (!array_key_exists('publicKey', $vapid)) {
            throw new \ErrorException('[VAPID] You must provide a public key.');
        }

        $publicKey = Base64Url::decode($vapid['publicKey']);

        if (Utils::safeStrlen($publicKey) !== 65) {
            throw new \ErrorException('[VAPID] Public key should be 65 bytes long when decoded.');
        }

        if (!array_key_exists('privateKey', $vapid)) {
            throw new \ErrorException('[VAPID] You must provide a private key.');
        }

        $privateKey = Base64Url::decode($vapid['privateKey']);

        if (Utils::safeStrlen($privateKey) !== 32) {
            throw new \ErrorException('[VAPID] Private key should be 32 bytes long when decoded.');
        }

        return array(
            'subject' => $vapid['subject'],
            'publicKey' => $publicKey,
            'privateKey' => $privateKey,
        );
    }

    /**
     * This method takes the required VAPID parameters and returns the required
     * header to be added to a Web Push Protocol Request.
     *
     * @param string $audience   This must be the origin of the push service
     * @param string $subject    This should be a URL or a 'mailto:' email address
     * @param string $publicKey  The decoded VAPID public key
     * @param string $privateKey The decoded VAPID private key
     * @param int    $expiration The expiration of the VAPID JWT. (UNIX timestamp)
     *
     * @return array Returns an array with the 'Authorization' and 'Crypto-Key' values to be used as headers
     */
    public static function getVapidHeaders($audience, $subject, $publicKey, $privateKey, $expiration = null)
{'fraction_non_alphanumeric': 0.10755239224990115, 'fraction_numerical': 0.006326611308817715, 'mean_word_length': 2.7529673590504453, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '5235299', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1446, 'n_words': 484}