cryptosphere/cryptosphere

View on GitHub
lib/cryptosphere.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'cryptosphere/version'

require 'celluloid'
require 'lattice'

require 'cryptosphere/block'
require 'cryptosphere/encoding'
require 'cryptosphere/pkt_line_reader'
require 'cryptosphere/position'

require 'cryptosphere/heads/read_head'
require 'cryptosphere/heads/write_head'

module Cryptosphere
  # Size of symmetric keys in bytes (32 bytes, 256-bits)
  SECRET_KEY_BYTES = RbNaCl::SecretBox::KEYBYTES

  # Secure random data source
  def self.random_bytes(size)
    RbNaCl::Random.random_bytes(size)
  end

  # The length prefix specifies a data segment longer than PKT_LEN_MAX
  class LengthError < ArgumentError; end

  # Malformatted data was encountered
  class FormatError < StandardError; end

  # An unexpected message was encountered
  class ProtocolError < FormatError; end

  # We are not in the correct state to perform the given action
  class StateError < StandardError; end

  # Request to do something we're incapable of
  class CapabilityError < StandardError; end

  # Signature doesn't match (potential data tampering)
  class ForgeryError < StandardError; end

  # Implausible timestamps (i.e. ones from the future)
  class InvalidTimestampError < StandardError; end

  def self.logger
    Celluloid.logger
  end
end