Class: Prototok::Formatters::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/prototok/formatters/default.rb

Instance Method Summary collapse

Instance Method Details

#decode(str) ⇒ Object



10
11
12
13
14
# File 'lib/prototok/formatters/default.rb', line 10

def decode(str)
  parts = str.split(Prototok.config[:token_delimiter])
  raise Errors::FormatError if parts.size != 2
  parts.map { |part| RbNaCl::Util.hex2bin(part) }
end

#encode(*args) ⇒ Object



4
5
6
7
8
# File 'lib/prototok/formatters/default.rb', line 4

def encode(*args)
  raise Errors::FormatError if args.size != 2
  args.map { |part| RbNaCl::Util.bin2hex(part) }
      .join(Prototok.config[:token_delimiter])
end