module Prototok

Constants

CLAIM_ALIASES
CONFIG_DEFAULTS
VERSION

Public Class Methods

config()
Alias for: configuration
configuration() click to toggle source
# File lib/prototok/config.rb, line 15
def configuration
  @configutation ||= CONFIG_DEFAULTS.dup
end
Also aliased as: config
configure() { |configuration| ... } click to toggle source
# File lib/prototok/config.rb, line 19
def configure
  yield(configuration)
end
decode(encoded=nil, *cipher_args, **opts) click to toggle source
# File lib/prototok.rb, line 23
def decode(encoded=nil, *cipher_args, **opts)
  raise ArgumentError if encoded.nil?
  unformatted = formatter(opts[:formatter]).new.decode(encoded)
  unprocessed = cipher(**opts).new(*cipher_args).decode(*unformatted)
  encoder_instance(**opts).decode(unprocessed)
end
encode(payload=nil, *cipher_args, **opts) click to toggle source
# File lib/prototok.rb, line 15
def encode(payload=nil, *cipher_args, **opts)
  raise ArgumentError if payload.nil?
  header = opts[:header] || {}
  encoded = encoder_instance(**opts).encode(payload, **header)
  processed = cipher(**opts).new(*cipher_args).encode(encoded)
  formatter(opts[:formatter]).new.encode(*processed)
end
key(*args, **opts) click to toggle source
# File lib/prototok.rb, line 30
def key(*args, **opts)
  cipher(**opts).key(*args)
end

Private Class Methods

cipher(op: nil, version: nil, **_) click to toggle source
# File lib/prototok.rb, line 45
def cipher(op: nil, version: nil, **_)
  op ||= config[:op]
  version ||= config[:version]
  ver_name = "V#{version}"
  Prototok::Ciphers.find(ver_name, op) || err(ArgumentError, :cipher)
end
encoder_instance(encoder: nil, encoder_options: nil, **_) click to toggle source
# File lib/prototok.rb, line 38
def encoder_instance(encoder: nil, encoder_options: nil, **_)
  encoder ||= config[:encoder]
  klass = Prototok::Encoders.find(encoder) || err(ArgumentError, :encoder)
  encoder_options ||= {}
  klass.new(**encoder_options)
end
formatter(frmter_name = nil) click to toggle source
# File lib/prototok.rb, line 52
def formatter(frmter_name = nil)
  frmter_name ||= config[:formatter]
  Prototok::Formatters.find(frmter_name) || err(ArgumentError, :formatter)
end