diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/models/token_with_iv.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/models/token_with_iv.rb')
-rw-r--r-- | app/models/token_with_iv.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/token_with_iv.rb b/app/models/token_with_iv.rb new file mode 100644 index 00000000000..115f40b4a82 --- /dev/null +++ b/app/models/token_with_iv.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# rubocop: todo Gitlab/NamespacedClass +class TokenWithIv < ApplicationRecord + validates :hashed_token, presence: true + validates :iv, presence: true + validates :hashed_plaintext_token, presence: true + + def self.find_by_hashed_token(value) + find_by(hashed_token: ::Digest::SHA256.digest(value)) + end + + def self.find_by_plaintext_token(value) + find_by(hashed_plaintext_token: ::Digest::SHA256.digest(value)) + end + + def self.find_nonce_by_hashed_token(value) + return unless table_exists? + + token_record = find_by_hashed_token(value) + token_record&.iv + end +end |