Class: Ironclad::Cache::Keyctl

Inherits:
Object
  • Object
show all
Defined in:
lib/ironclad/cache/keyctl.rb

Overview

Linux kernel keyring via ‘keyctl`, stored in the user keyring (@u): it persists across this user’s sessions and clears on reboot, at which point a miss simply re-seeds from the source.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/ironclad/cache/keyctl.rb', line 11

def self.available?
  ENV['PATH'].to_s.split(File::PATH_SEPARATOR).any? do |dir|
    File.executable?(File.join(dir, 'keyctl'))
  end
end

Instance Method Details

#read(name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/ironclad/cache/keyctl.rb', line 17

def read(name)
  id, status = Open3.capture2('keyctl', 'search', '@u', 'user', name)
  return unless status.success?

  out, status = Open3.capture2('keyctl', 'pipe', id.chomp)
  status.success? ? out : nil
end

#write(name, key) ⇒ Object



25
26
27
# File 'lib/ironclad/cache/keyctl.rb', line 25

def write(name, key)
  Open3.capture2('keyctl', 'padd', 'user', name, '@u', stdin_data: key)
end