Class: Kingdom::King

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute key to.



10
11
12
# File 'lib/kingdom.rb', line 10

def key=(value)
  @key = value
end

#passObject

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/kingdom.rb', line 25

def private? x
  key { |k| if k[:private]; return true; else; return false; end; }
end

#publicObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

def sign? sig, doc
  key { |x| x.valid?(sig, doc) }
end