Class: Kingdom::King
- Inherits:
-
Object
- Object
- Kingdom::King
- Defined in:
- lib/kingdom.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
writeonly
Sets the attribute key.
-
#pass ⇒ Object
Returns the value of attribute pass.
Instance Method Summary collapse
-
#<<(i) ⇒ Object
encrypt string.
-
#[](i) ⇒ Object
decrypt string.
-
#initialize(i) ⇒ King
constructor
A new instance of King.
-
#lock(password) ⇒ Object
lock key.
-
#peek(&b) ⇒ Object
return new private key.
-
#private?(x) ⇒ Boolean
validate private key.
-
#public ⇒ Object
return public key.
-
#public?(x) ⇒ Boolean
validate public key.
-
#sign(doc) ⇒ Object
sign doc with key.
-
#sign?(sig, doc) ⇒ Boolean
validate signature for key.
Constructor Details
#initialize(i) ⇒ King
Returns a new instance of King.
11 12 13 |
# File 'lib/kingdom.rb', line 11 def initialize i @id = i end |
Instance Attribute Details
#key=(value) ⇒ Object
Sets the attribute key
10 11 12 |
# File 'lib/kingdom.rb', line 10 def key=(value) @key = value end |
#pass ⇒ Object
Returns the value of attribute pass.
10 11 12 |
# File 'lib/kingdom.rb', line 10 def pass @pass end |
Instance Method Details
#<<(i) ⇒ Object
encrypt string
59 60 61 |
# File 'lib/kingdom.rb', line 59 def << i box { |b| b << i } end |
#[](i) ⇒ Object
decrypt string
64 65 66 |
# File 'lib/kingdom.rb', line 64 def [] i box { |b| b[i] } end |
#lock(password) ⇒ Object
lock key
44 45 46 |
# File 'lib/kingdom.rb', line 44 def lock password key { |x| x.lock(password) { |e| Kingdom.encode(e) } } end |
#peek(&b) ⇒ Object
return new private key
16 17 18 19 20 21 22 |
# File 'lib/kingdom.rb', line 16 def peek &b if block_given? key { |k| b.call(Kingdom.encode(k[:private])) } else key { |k| Kingdom.encode(k[:private]) } end end |
#private?(x) ⇒ Boolean
validate private key
25 26 27 |
# File 'lib/kingdom.rb', line 25 def private? x key { |k| if k[:private]; return true; else; return false; end; } end |
#public ⇒ Object
return public key
30 31 32 |
# File 'lib/kingdom.rb', line 30 def public key { |k| k[:public]; } end |
#public?(x) ⇒ Boolean
validate public key
35 36 37 38 39 40 41 |
# File 'lib/kingdom.rb', line 35 def public? x if x == public; return true; else; return false; end; end |
#sign(doc) ⇒ Object
sign doc with key
49 50 51 |
# File 'lib/kingdom.rb', line 49 def sign doc key { |x| x.sign(doc) } end |
#sign?(sig, doc) ⇒ Boolean
validate signature for key
54 55 56 |
# File 'lib/kingdom.rb', line 54 def sign? sig, doc key { |x| x.valid?(sig, doc) } end |