<commit_before>class SessionToken

  def self.missing_env(name)
    raise "You forgot to set ENV['#{ name }']"
  end

  HOST         = Rails.application.routes.default_url_options[:host]
  PORT         = Rails.application.routes.default_url_options[:port]
  EXPIRY       = 40.days
  PRIVATE_KEY  = KeyGen.current
  PUBLIC_KEY   = KeyGen.current.public_key
  ALG          = 'RS256'
  MQTT         = ENV['MQTT_HOST']  || missing_env('MQTT_HOST')
  OS_RELEASE   = ENV['OS_UPDATE_SERVER'] || missing_env('OS_UPDATE_SERVER')
  FW_RELEASE   = ENV['FW_UPDATE_SERVER'] || missing_env('FW_UPDATE_SERVER')

  attr_accessor :encoded, :unencoded
  def initialize(payload)
    @unencoded = payload[0]
    @encoded   = JWT.encode(payload[0], PRIVATE_KEY, ALG)
  end

  def self.decode!(token)
    self.new JWT.decode(token, PUBLIC_KEY, true, algorithm: ALG)
  end

  def self.issue_to(user,
                    iat: Time.now.to_i,
                    exp: EXPIRY.from_now.to_i,
                    iss: "http://#{ HOST }:#{ PORT }")

    self.new([{
             sub:  user.email,
             iat:  iat,
             jti:  SecureRandom.uuid, # TODO: Add ability to revoke.
             iss:  iss,
             exp:  exp,
             mqtt: MQTT,
             os_update_server: OS_RELEASE,
             fw_update_server: FW_RELEASE,
             bot:  user.device.id}])
  end
end<commit_msg>[BREAKING CHANGE] MQTT.js doesnt like short IDs, so we will use `deivce_1` instead of `1`<commit_after>class SessionToken

  def self.missing_env(name)
    raise "You forgot to set ENV['#{ name }']"
  end

  HOST         = Rails.application.routes.default_url_options[:host]
  PORT         = Rails.application.routes.default_url_options[:port]
  EXPIRY       = 40.days
  PRIVATE_KEY  = KeyGen.current
  PUBLIC_KEY   = KeyGen.current.public_key
  ALG          = 'RS256'
  MQTT         = ENV['MQTT_HOST']  || missing_env('MQTT_HOST')
  OS_RELEASE   = ENV['OS_UPDATE_SERVER'] || missing_env('OS_UPDATE_SERVER')
  FW_RELEASE   = ENV['FW_UPDATE_SERVER'] || missing_env('FW_UPDATE_SERVER')

  attr_accessor :encoded, :unencoded
  def initialize(payload)
    @unencoded = payload[0]
    @encoded   = JWT.encode(payload[0], PRIVATE_KEY, ALG)
  end

  def self.decode!(token)
    self.new JWT.decode(token, PUBLIC_KEY, true, algorithm: ALG)
  end

  def self.issue_to(user,
                    iat: Time.now.to_i,
                    exp: EXPIRY.from_now.to_i,
                    iss: "http://#{ HOST }:#{ PORT }")

    self.new([{
             sub:  user.email,
             iat:  iat,
             jti:  SecureRandom.uuid, # TODO: Add ability to revoke.
             iss:  iss,
             exp:  exp,
             mqtt: MQTT,
             os_update_server: OS_RELEASE,
             fw_update_server: FW_RELEASE,
             bot:  "device_#{user.device.id}"])
  end
end
{'fraction_non_alphanumeric': 0.11545230552622317, 'fraction_numerical': 0.005631819781766983, 'mean_word_length': 2.251716247139588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6233273', 'n_tokens_mistral': 1033, 'n_tokens_neox': 964, 'n_words': 193}