Class: Prototok::Ciphers::V1::Sign

Inherits:
Base
  • Object
show all
Defined in:
lib/prototok/ciphers/V1/sign.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cipher_class

Constructor Details

#initialize(private_or_public_key) ⇒ Sign

Returns a new instance of Sign.



9
10
11
# File 'lib/prototok/ciphers/V1/sign.rb', line 9

def initialize(private_or_public_key)
  @key = private_or_public_key
end

Class Method Details

.key(private_key = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/prototok/ciphers/V1/sign.rb', line 24

def self.key(private_key = nil)
  if private_key.nil?
    cipher_class::SigningKey.generate.to_bytes
  else
    cipher_class::SigningKey.new(private_key).verify_key.to_bytes
  end
end

Instance Method Details

#decode(decoded_auth, decoded_blob) ⇒ Object



18
19
20
21
22
# File 'lib/prototok/ciphers/V1/sign.rb', line 18

def decode(decoded_auth, decoded_blob)
  cipher = cipher_class::VerifyKey.new(@key)
  cipher.verify(decoded_auth, decoded_blob)
  decoded_blob
end

#encode(blob) ⇒ Object



13
14
15
16
# File 'lib/prototok/ciphers/V1/sign.rb', line 13

def encode(blob)
  cipher = cipher_class::SigningKey.new(@key)
  [cipher.sign(blob), blob]
end