module JwtNacl::Util

Utility methods

Constants

ED25519_SEEDBYTES

Public Instance Methods

ed25519_random_seed() click to toggle source
# File lib/jwt_nacl/util.rb, line 11
def ed25519_random_seed
  RbNaCl::Random.random_bytes(ED25519_SEEDBYTES)
end
symbolize_keys(hsh) click to toggle source

@param hsh [Hash] @return [Hash] a new hash with all keys converted to symbols,

provided that they respond to .to_sym

@example

Util.symbolize_keys({"a" =>  0, "b" => "2", c: "3"})
# => {a: 0, b: "2", c: "3"}

@see cf. rails activesupport/lib/active_support/core_ext/hash/keys.rb

# File lib/jwt_nacl/util.rb, line 22
def symbolize_keys(hsh)
  transform_keys(hsh) { |key| key.to_sym rescue key }
end
transform_keys(hsh) { |k| ... } click to toggle source
# File lib/jwt_nacl/util.rb, line 26
def transform_keys(hsh)
  result = Hash.new
  hsh.keys.each { |k| result[yield(k)] = hsh[k] }
  result
end