Class: Zold::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/key.rb

Overview

A key

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Key.



31
32
33
34
35
36
37
38
# File 'lib/zold/key.rb', line 31

def initialize(file: nil, text: nil)
  unless file.nil?
    path = File.expand_path(file)
    raise "Can't find RSA key at #{file} (#{path})" unless File.exist?(path)
    @body = File.read(path)
  end
  @body = text unless text.nil?
end

Instance Method Details

#sign(text) ⇒ Object



44
45
46
# File 'lib/zold/key.rb', line 44

def sign(text)
  Base64.encode64(rsa.sign(OpenSSL::Digest::SHA256.new, text)).delete("\n")
end

#to_sObject



40
41
42
# File 'lib/zold/key.rb', line 40

def to_s
  rsa.to_s.strip
end

#verify(signature, text) ⇒ Object



48
49
50
# File 'lib/zold/key.rb', line 48

def verify(signature, text)
  rsa.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), text)
end