Class: Prototok::Ciphers::V1::EncryptedMac

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

Instance Method Summary collapse

Methods inherited from Base

#cipher_class, key

Constructor Details

#initialize(private_key) ⇒ EncryptedMac

Returns a new instance of EncryptedMac.



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

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

Instance Method Details

#decode(decoded_nonce, decoded_blob) ⇒ Object



18
19
20
# File 'lib/prototok/ciphers/V1/encrypted_mac.rb', line 18

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

#encode(blob) ⇒ Object



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

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