Class: Kingdom::Key
- Inherits:
-
Object
- Object
- Kingdom::Key
- Defined in:
- lib/kingdom/key.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(k) ⇒ Key
constructor
A new instance of Key.
-
#lock(pass, &b) ⇒ Object
export key with password.
-
#sign(doc) ⇒ Object
sign document with key.
- #to_h ⇒ Object
-
#valid?(sig, doc) ⇒ Boolean
validate document with signature.
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
#key ⇒ Object (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_h ⇒ Object
54 55 56 |
# File 'lib/kingdom/key.rb', line 54 def to_h @h end |