Class: ScripTTY::Net::PasswordPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/scriptty/net/password_prompt.rb

Constant Summary collapse

IAC_WILL_ECHO =
"\377\373\001"
IAC_WONT_ECHO =
"\377\374\001"
IAC_DO_ECHO =
"\377\375\001"
IAC_DONT_ECHO =
"\377\376\001"

Instance Method Summary collapse

Constructor Details

#initialize(conn, prompt = "Password: ") ⇒ PasswordPrompt

Returns a new instance of PasswordPrompt.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/scriptty/net/password_prompt.rb', line 9

def initialize(conn, prompt="Password: ")
  @conn = conn
  @conn.write(IAC_WILL_ECHO + IAC_DONT_ECHO) if prompt    # echo off
  @conn.write(prompt) if prompt
  @conn.on_receive_bytes { |bytes|
    bytes.split("").each { |byte|
      handle_received_byte(byte) unless @done   # XXX - This doesn't work well with pipelining; we throw away bytes after the prompt is finished.
    }
  }
  @password_buffer = ""
  @done = false
end

Instance Method Details

#authenticate(&block) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
# File 'lib/scriptty/net/password_prompt.rb', line 22

def authenticate(&block)
  raise ArgumentError.new("no block given") unless block
  @authenticate_proc = block
  nil
end

#on_fail(&block) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
# File 'lib/scriptty/net/password_prompt.rb', line 28

def on_fail(&block)
  raise ArgumentError.new("no block given") unless block
  @fail_proc = block
  nil
end

#on_success(&block) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/scriptty/net/password_prompt.rb', line 34

def on_success(&block)
  raise ArgumentError.new("no block given") unless block
  @success_proc = block
  nil
end