Sha256: 08cf39a8316d3d9e6661d55a5d264062126a73ed29865475497ff74308cbd6b1

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

module ShadowsocksRuby
  module Protocols

    # To be used with protocols without an IV, like {Cipher::Table}
    class NoIvCipherProtocol
      include DummyHelper

      attr_accessor :next_protocol

      # @param [Hash]                                                     configuration parameters
      # @option params [Cipher::Table] :cipher                            a cipher object without IV,  +required+
      def initialize params = {}
        @cipher = params[:cipher] or raise ProtocolError, "params[:cipher] is required"
      end

      def tcp_receive_from_remoteserver n
        @cipher.decrypt(async_recv n)
      end

      def tcp_send_to_remoteserver data
        send_data(@cipher.encrypt data)
      end

      def tcp_receive_from_localbackend n
        @cipher.decrypt(async_recv n)
      end

      def tcp_send_to_localbackend data
        send_data(@cipher.encrypt data)
      end

      private

      alias tcp_receive_from_client raise_me
      alias tcp_send_to_client raise_me
      #alias tcp_receive_from_remoteserver raise_me
      #alias tcp_send_to_remoteserver raise_me
      #alias tcp_receive_from_localbackend raise_me
      #alias tcp_send_to_localbackend raise_me
      alias tcp_receive_from_destination raise_me
      alias tcp_send_to_destination raise_me

      alias udp_receive_from_client raise_me
      alias udp_send_to_client raise_me
      alias udp_receive_from_remoteserver raise_me
      alias udp_send_to_remoteserver raise_me
      alias udp_receive_from_localbackend raise_me
      alias udp_send_to_localbackend raise_me
      alias udp_receive_from_destination raise_me
      alias udp_send_to_destination raise_me
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shadowsocks_ruby-0.1.2 lib/shadowsocks_ruby/protocols/cipher/no_iv_cipher.rb
shadowsocks_ruby-0.1.1 lib/shadowsocks_ruby/protocols/cipher/no_iv_cipher.rb
shadowsocks_ruby-0.1.0 lib/shadowsocks_ruby/protocols/cipher/no_iv_cipher.rb