Class: Kingdom::Key

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(k) ⇒ Key

Returns a new instance of Key.



35
36
37
38
# File 'lib/kingdom/key.rb', line 35

def initialize k
  @key = k
  @h = { private: @key.to_s, public: @key.public_key.to_s }
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



34
35
36
# File 'lib/kingdom/key.rb', line 34

def key
  @key
end

Instance Method Details

#[](k) ⇒ Object



51
52
53
# File 'lib/kingdom/key.rb', line 51

def [] k
  @h[k]
end

#lock(pass, &b) ⇒ Object

export key with password



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

def lock pass, &b
  b.call(@key.export(Kingdom.cipher, pass))
end

#sign(doc) ⇒ Object

sign document with key



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

def sign doc
  Kingdom.encode(@key.sign(Kingdom.digest, doc))
end

#to_hObject



54
55
56
# File 'lib/kingdom/key.rb', line 54

def to_h
  @h
end

#valid?(sig, doc) ⇒ Boolean

validate document with signature

Returns:

  • (Boolean)


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

def valid? sig, doc
  @key.verify(Kingdom.digest, Kingdom.decode(sig), doc)
end