<commit_before><?php

namespace React\SocketClient;

use React\Promise\ResolverInterface;
use React\Promise\Deferred;
use React\Stream\Stream;
use React\EventLoop\LoopInterface;
use \UnexpectedValueException;
use \InvalidArgumentException;

// this class is considered internal and its API should not be relied upon outside of React\SocketClient
class StreamEncryption
{
    protected $loop;
    protected $method = STREAM_CRYPTO_METHOD_TLS_CLIENT;

    public function __construct(LoopInterface $loop)
    {
        $this->loop = $loop;
    }

    public function setMethod($method)
    {
//         if (!in_array($method, array(), true)) {
//             throw new InvalidArgumentException('Invalid encryption method given');
//         }
        $this->method = $method;
    }

    public function enable(Stream $stream)
    {
        return $this->toggle($stream, true);
    }

    public function disable(Stream $stream)
    {
        return $this->toggle($stream, false);
    }

    public function toggle(Stream $stream, $toggle)
    {
        // pause actual stream instance to continue operation on raw stream socket
        $stream->pause();

        // TODO: add write() event to make sure we're not sending any excessive data

        $deferred = new Deferred();

        // get actual stream socket from stream instance
        $socket = $stream->stream;

        $that = $this;
        $toggleCrypto = function () use ($that, $socket, $deferred, $toggle) {
            $that->toggleCrypto($socket, $deferred, $toggle);
        };

        $this->loop->addWriteStream($socket, $toggleCrypto);
        $this->loop->addReadStream($socket, $toggleCrypto);<commit_msg>Remove useless setter for the time being<commit_after><?php

namespace React\SocketClient;

use React\Promise\ResolverInterface;
use React\Promise\Deferred;
use React\Stream\Stream;
use React\EventLoop\LoopInterface;
use \UnexpectedValueException;
use \InvalidArgumentException;

// this class is considered internal and its API should not be relied upon outside of React\SocketClient
class StreamEncryption
{
    protected $loop;
    protected $method = STREAM_CRYPTO_METHOD_TLS_CLIENT;

    public function __construct(LoopInterface $loop)
    {
        $this->loop = $loop;
    }

    public function enable(Stream $stream)
    {
        return $this->toggle($stream, true);
    }

    public function disable(Stream $stream)
    {
        return $this->toggle($stream, false);
    }

    public function toggle(Stream $stream, $toggle)
    {
        // pause actual stream instance to continue operation on raw stream socket
        $stream->pause();

        // TODO: add write() event to make sure we're not sending any excessive data

        $deferred = new Deferred();

        // get actual stream socket from stream instance
        $socket = $stream->stream;

        $that = $this;
        $toggleCrypto = function () use ($that, $socket, $deferred, $toggle) {
            $that->toggleCrypto($socket, $deferred, $toggle);
        };

        $this->loop->addWriteStream($socket, $toggleCrypto);
        $this->loop->addReadStream($socket, $toggleCrypto);
{'fraction_non_alphanumeric': 0.10937996820349762, 'fraction_numerical': 0.0, 'mean_word_length': 2.9622166246851385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '3668122', 'n_tokens_mistral': 852, 'n_tokens_neox': 827, 'n_words': 252}