Method: Zold::Key#initialize

Defined in:
lib/zold/key.rb

#initialize(file: nil, text: nil) ⇒ Key

Returns a new instance of Key.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zold/key.rb', line 33

def initialize(file: nil, text: nil)
  @body = lambda do
    unless file.nil?
      path = File.expand_path(file)
      raise "Can't find RSA key at #{file} (#{path})" unless File.exist?(path)
      return File.read(path)
    end
    unless text.nil?
      return [
        '-----BEGIN PUBLIC KEY-----',
        text.gsub(/(?<=\G.{64})/, "\n"),
        '-----END PUBLIC KEY-----'
      ].join("\n")
    end
    raise 'Either file or text must be set'
  end
end