<commit_before>class SessionToken
  PASSWORD = Rails.application.secrets.secret_key_base
  EXPIRY   = 4.days
  ISSUER   = 'farmbot-web-app'

  attr_accessor :encoded, :unencoded

  def initialize(payload)
    @unencoded = payload
    @encoded   = JWT.encode(payload, PASSWORD)
  end

  def self.decode!(token)
    self.new JWT.decode(token, PASSWORD)
  end

  def self.issue_to(user, iat = Time.now.to_i, exp = EXPIRY.from_now.to_i)
    self.new(sub: user.email,
             iat: iat,
             jti: SecureRandom.uuid, # TODO: Add ability to revoke.
             iss: ISSUER,
             exp: exp,
             alg: "RS256")
  end
end<commit_msg>Change JWT encrytion to RS256<commit_after>class SessionToken
  EXPIRY       = 4.days
  ISSUER       = 'farmbot-web-app'
  PRIVATE_KEY  = KeyGen.current
  PUBLIC_KEY   = KeyGen.current.public_key
  ALG          = 'RS256'

  attr_accessor :encoded, :unencoded

  def initialize(payload)
    @unencoded = payload
    @encoded   = JWT.encode(payload, 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)
    self.new(sub: user.email,
             iat: iat,
             jti: SecureRandom.uuid, # TODO: Add ability to revoke.
             iss: ISSUER,
             exp: exp,
             alg: ALG)
  end
end
{'fraction_non_alphanumeric': 0.10150107219442459, 'fraction_numerical': 0.007862759113652609, 'mean_word_length': 2.389830508474576, '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': '7618709', 'n_tokens_mistral': 536, 'n_tokens_neox': 499, 'n_words': 111}