Class: SocksHandler::UsernamePasswordAuthenticator
- Inherits:
-
Object
- Object
- SocksHandler::UsernamePasswordAuthenticator
- Defined in:
- lib/socks_handler/username_password_authenticator.rb
Overview
An implementation of www.ietf.org/rfc/rfc1929.txt
Constant Summary collapse
- SUBNEGOTIATION_VERSION =
0x01
Instance Method Summary collapse
- #authenticate(socket) ⇒ nil
-
#initialize(username, password) ⇒ UsernamePasswordAuthenticator
constructor
A new instance of UsernamePasswordAuthenticator.
Constructor Details
#initialize(username, password) ⇒ UsernamePasswordAuthenticator
Returns a new instance of UsernamePasswordAuthenticator.
12 13 14 15 16 17 18 |
# File 'lib/socks_handler/username_password_authenticator.rb', line 12 def initialize(username, password) raise ArgumentError, "Username is too long" if username.bytesize > 256 raise ArgumentError, "Password is too long" if password.bytesize > 256 @username = username @password = password end |
Instance Method Details
#authenticate(socket) ⇒ nil
22 23 24 25 26 27 28 29 |
# File 'lib/socks_handler/username_password_authenticator.rb', line 22 def authenticate(socket) socket.write([SUBNEGOTIATION_VERSION, @username.bytesize, @username, @password.bytesize, @password].pack("CCa*Ca*")) _version, status = socket.recv(2).unpack("C*") if status != 0x00 raise AuthenticationFailure, "username: #{@username}, status: #{status}" end nil end |