module Roda::RodaPlugins::HmacPaths

def self.configure(app, opts=OPTS)

def self.configure(app, opts=OPTS)
  hmac_secret = opts[:secret]
  unless hmac_secret.is_a?(String) && hmac_secret.bytesize >= 32
    raise RodaError, "hmac_paths plugin :secret option must be a string containing at least 32 bytes"
  end
  if hmac_old_secret = opts[:old_secret]
    unless hmac_old_secret.is_a?(String) && hmac_old_secret.bytesize >= 32
      raise RodaError, "hmac_paths plugin :old_secret option must be a string containing at least 32 bytes if present"
    end
  end
  app.opts[:hmac_paths_secret] = hmac_secret
  app.opts[:hmac_paths_old_secret] = hmac_old_secret
  if opts[:namespace_session_key]
    app.opts[:hmac_paths_namespace_session_key] = opts[:namespace_session_key]
  end
end