Class: Pwsafe::Agent::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/pwsafe-agent/driver.rb

Instance Method Summary collapse

Constructor Details

#initializeDriver

Returns a new instance of Driver.



4
5
6
# File 'lib/pwsafe-agent/driver.rb', line 4

def initialize
  @password = nil
end

Instance Method Details

#blank_password?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/pwsafe-agent/driver.rb', line 32

def blank_password? 
  @password == ''
end

#flushObject



25
26
27
28
29
30
# File 'lib/pwsafe-agent/driver.rb', line 25

def flush 
  UNIXSocket.open(SOCKET_PATH) do |sock| 
    sock.write "FLUSH"
    sock.close
  end
end

#getObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pwsafe-agent/driver.rb', line 36

def get 
  UNIXSocket.open(SOCKET_PATH) do |sock| 
    sock.write 'GET'
    sock.close_write

    @password = sock.read
    sock.close
  end

  set if blank_password? 
  @password
end

#setObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pwsafe-agent/driver.rb', line 8

def set 
  UNIXSocket.open(SOCKET_PATH) do |sock| 
    puts "type password"
    begin 
      system 'stty -echo' 
      password = STDIN.gets.chomp 
    ensure 
      system 'stty echo' 
    end
    sock.write "SET=#{password}" 
    sock.close_write

    @password = sock.read
    sock.close
  end
end