Module: LcpRuby::ApiTokens::TokenGenerator
- Defined in:
- lib/lcp_ruby/api_tokens/token_generator.rb
Constant Summary collapse
- PREFIX =
"lcp_pat_".freeze
- PREFIX_DISPLAY_LENGTH =
12
Class Method Summary collapse
- .generate ⇒ Object
- .hash(plaintext) ⇒ Object
- .prefix(plaintext) ⇒ Object
- .valid_format?(token) ⇒ Boolean
Class Method Details
.generate ⇒ Object
10 11 12 |
# File 'lib/lcp_ruby/api_tokens/token_generator.rb', line 10 def self.generate "#{PREFIX}#{SecureRandom.urlsafe_base64(32)}" end |
.hash(plaintext) ⇒ Object
14 15 16 |
# File 'lib/lcp_ruby/api_tokens/token_generator.rb', line 14 def self.hash(plaintext) Digest::SHA256.hexdigest(plaintext.to_s) end |
.prefix(plaintext) ⇒ Object
18 19 20 |
# File 'lib/lcp_ruby/api_tokens/token_generator.rb', line 18 def self.prefix(plaintext) plaintext.to_s[0, PREFIX_DISPLAY_LENGTH] end |
.valid_format?(token) ⇒ Boolean
22 23 24 |
# File 'lib/lcp_ruby/api_tokens/token_generator.rb', line 22 def self.valid_format?(token) token.to_s.start_with?(PREFIX) end |