<commit_before><?php

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2015 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace SpomkyLabs\JoseBundle\Model;

use Jose\JWKInterface;
use SpomkyLabs\Jose\JWKSetManager;
use SpomkyLabs\Jose\KeyConverter\ECKey;
use SpomkyLabs\Jose\KeyConverter\KeyConverter;
use SpomkyLabs\Jose\KeyConverter\RSAKey;

class KeysetManager extends JWKSetManager implements KeysetManagerInterface
{
    /**
     * @var \Jose\JWKSetInterface
     */
    protected $private_keyset;

    /**
     * @var \Jose\JWKSetInterface
     */
    protected $public_keyset;

    /**
     * @var \Jose\JWKSetInterface
     */
    protected $asymmetric_keyset;

    /**
     * @var \Jose\JWKSetInterface
     */
    protected $shared_keyset;

    /**
     * @return \string[]
     */
    public function getKeysetNames()
    {
        return [
            self::KEYSET_PRIVATE,
            self::KEYSET_PUBLIC,
            self::KEYSET_ASYMMETRIC,
        ];
    }

    /**
     *
     */
    public function __construct()
    {
        $this->private_keyset = $this->createJWKSet();
        $this->public_keyset = $this->createJWKSet();
        $this->asymmetric_keyset = $this->createJWKSet();
        $this->shared_keyset = $this->createJWKSet();
    }

    /**
     * {@inheritdoc}
     */
    public function getKeyset($name)
    {
        if (!in_array($name, $this->getKeysetNames())) {
            throw new \InvalidArgumentException(sprintf('Unknown key set. Please use one of the following name: %s', json_encode($this->getKeysetNames())));
        }
        $method = 'get'. ucfirst($name).'Keyset';
        if (!in_array($name, $this->getKeysetNames())) {
            throw new \RuntimeException(sprintf('Unknown method "%s".', $method));
        }

        return $this->$method();
    }

    /**
     * {@inheritdoc}
     */
    public function getPublicKeyset()
    {
        return $this->public_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function getPrivateKeyset()
    {
        return $this->private_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function getAsymmetricKeyset()
    {
        return $this->asymmetric_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function getSharedKeyset()
    {
        return $this->shared_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function findKeyById($id, array $keysets = [])
    {
        if (empty($keysets)) {
            $keysets = $this->getKeysetNames();
        }
        foreach ($keysets as $name) {
            $keyset = $this->getKeyset($name);
            foreach ($keyset->getKeys() as $key) {
                if ($key->getKeyID()) {
                    return $key;
                }
            }
        }
    }<commit_msg>bug fixed<commit_after><?php

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2015 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace SpomkyLabs\JoseBundle\Model;

use Jose\JWKInterface;
use SpomkyLabs\Jose\JWKSetManager;
use SpomkyLabs\Jose\KeyConverter\ECKey;
use SpomkyLabs\Jose\KeyConverter\KeyConverter;
use SpomkyLabs\Jose\KeyConverter\RSAKey;

class KeysetManager extends JWKSetManager implements KeysetManagerInterface
{
    /**
     * @var \Jose\JWKSetInterface
     */
    protected $private_keyset;

    /**
     * @var \Jose\JWKSetInterface
     */
    protected $public_keyset;

    /**
     * @var \Jose\JWKSetInterface
     */
    protected $asymmetric_keyset;

    /**
     * @var \Jose\JWKSetInterface
     */
    protected $shared_keyset;

    /**
     * @return \string[]
     */
    public function getKeysetNames()
    {
        return [
            self::KEYSET_PRIVATE,
            self::KEYSET_PUBLIC,
            self::KEYSET_ASYMMETRIC,
        ];
    }

    /**
     *
     */
    public function __construct()
    {
        $this->private_keyset = $this->createJWKSet();
        $this->public_keyset = $this->createJWKSet();
        $this->asymmetric_keyset = $this->createJWKSet();
        $this->shared_keyset = $this->createJWKSet();
    }

    /**
     * {@inheritdoc}
     */
    public function getKeyset($name)
    {
        if (!in_array($name, $this->getKeysetNames())) {
            throw new \InvalidArgumentException(sprintf('Unknown key set. Please use one of the following name: %s', json_encode($this->getKeysetNames())));
        }
        $method = 'get'. ucfirst($name).'Keyset';
        if (!in_array($name, $this->getKeysetNames())) {
            throw new \RuntimeException(sprintf('Unknown method "%s".', $method));
        }

        return $this->$method();
    }

    /**
     * {@inheritdoc}
     */
    public function getPublicKeyset()
    {
        return $this->public_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function getPrivateKeyset()
    {
        return $this->private_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function getAsymmetricKeyset()
    {
        return $this->asymmetric_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function getSharedKeyset()
    {
        return $this->shared_keyset;
    }

    /**
     * {@inheritdoc}
     */
    public function findKeyById($id, array $keysets = [])
    {
        if (empty($keysets)) {
            $keysets = $this->getKeysetNames();
        }
        foreach ($keysets as $name) {
            $keyset = $this->getKeyset($name);
            foreach ($keyset->getKeys() as $key) {
                if ($id === $key->getKeyID()) {
                    return $key;
                }
            }
        }
    }
{'fraction_non_alphanumeric': 0.1379071379071379, 'fraction_numerical': 0.002772002772002772, 'mean_word_length': 2.0256813417190775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '1168389', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1793, 'n_words': 334}