Class: SocksTunnel::Coder
- Inherits:
-
Object
- Object
- SocksTunnel::Coder
- Defined in:
- lib/socks_tunnel/coder.rb
Instance Method Summary collapse
- #decode(data) ⇒ Object
- #encode(data) ⇒ Object
-
#initialize ⇒ Coder
constructor
A new instance of Coder.
Constructor Details
#initialize ⇒ Coder
Returns a new instance of Coder.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/socks_tunnel/coder.rb', line 5 def initialize cipher = OpenSSL::Cipher.new(Config.cipher) key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(Config.password, Config.salt, 2000, cipher.key_len + cipher.iv_len) @key = key_iv[0, cipher.key_len] @iv = key_iv[cipher.key_len, cipher.iv_len] @encoder = OpenSSL::Cipher.new(Config.cipher) @encoder.encrypt @encoder.key = @key @decoder = OpenSSL::Cipher.new(Config.cipher) @decoder.decrypt @decoder.key = @key end |
Instance Method Details
#decode(data) ⇒ Object
25 26 27 28 |
# File 'lib/socks_tunnel/coder.rb', line 25 def decode(data) @decoder.iv = @iv @decoder.update(data) + @decoder.final end |
#encode(data) ⇒ Object
20 21 22 23 |
# File 'lib/socks_tunnel/coder.rb', line 20 def encode(data) @encoder.iv = @iv @encoder.update(data) + @encoder.final end |