summaryrefslogtreecommitdiff
path: root/app/models/token_with_iv.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/token_with_iv.rb')
-rw-r--r--app/models/token_with_iv.rb23
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