Class: Prototok::Ciphers::V1::EncryptedSign

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cipher_class

Constructor Details

#initialize(private_key, remote_public_key) ⇒ EncryptedSign

Returns a new instance of EncryptedSign.



9
10
11
12
13
# File 'lib/prototok/ciphers/V1/encrypted_sign.rb', line 9

def initialize(private_key, remote_public_key)
  @private_key = private_key
  @remote_public_key = remote_public_key
  @cipher = cipher_class.new(@remote_public_key, @private_key)
end

Class Method Details

.key(private_key = nil) ⇒ Object



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

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

Instance Method Details

#decode(decoded_nonce, decoded_blob) ⇒ Object



20
21
22
# File 'lib/prototok/ciphers/V1/encrypted_sign.rb', line 20

def decode(decoded_nonce, decoded_blob)
  @cipher.decrypt(decoded_nonce, decoded_blob)
end

#encode(blob) ⇒ Object



15
16
17
18
# File 'lib/prototok/ciphers/V1/encrypted_sign.rb', line 15

def encode(blob)
  nonce = RbNaCl::Random.random_bytes(cipher_class.nonce_bytes)
  [nonce, @cipher.encrypt(nonce, blob)]
end