Class: EncodedToken::Configuration
- Inherits:
-
Object
- Object
- EncodedToken::Configuration
- Includes:
- ErrorMessages, Utils
- Defined in:
- lib/encoded_token/configuration.rb
Overview
EncodedToken::Configuration
This class manages the single configuration instance for EncodedToken.
Constant Summary collapse
- DEFAULT_CIPHER_COUNT =
======================================================================
Constants
======================================================================
16- DEFAULT_MIN_TOKEN_SIZE =
55- DEFAULT_MAX_INPUT_SIZE =
1000
Constants included from ErrorMessages
ErrorMessages::CIPHER_ERRORS, ErrorMessages::CONFIG_ERRORS, ErrorMessages::ENCODED_TOKEN_ERRORS, ErrorMessages::ENCODER_ERRORS, ErrorMessages::ENCRYPTOR_ERRORS, ErrorMessages::ERROR_MESSAGES, ErrorMessages::V1_ENCODER_ERRORS
Class Method Summary collapse
-
.instance ⇒ Configuration
Returns the singleton instance of the Configuration.
-
.lock! ⇒ true
Locks the configuration to prevent further changes.
-
.locked? ⇒ Boolean
Checks if the configuration is locked.
-
.unlock! ⇒ false
Unlocks the configuration.
-
.unlocked? ⇒ Boolean
Checks if the configuration is unlocked.
Instance Method Summary collapse
-
#add_expiring_seed(expiring_seed, expiry_date, cipher_count = DEFAULT_CIPHER_COUNT) ⇒ Hash
Adds an expiring seed to the configuration.
-
#cipher_count ⇒ Integer
Returns the default cipher count.
-
#cipher_count=(new_count) ⇒ Object
Sets the default cipher count.
-
#expiring_seeds ⇒ Hash<Integer, Hash>
Returns the map of expiring seeds.
-
#initialize ⇒ Configuration
constructor
= Instance Methods ======================================================================.
-
#lock! ⇒ true
Locks the configuration.
-
#locked? ⇒ Boolean
Checks if the configuration is locked.
-
#max_input_size ⇒ Integer
Returns the maximum input size.
-
#max_input_size=(max_size) ⇒ Object
Sets the maximum input size.
-
#min_token_size ⇒ Integer
Returns the minimum token size.
-
#min_token_size=(min_size) ⇒ Object
Sets the minimum token size.
-
#seed ⇒ Integer
Returns the master seed.
-
#seed=(new_seed) ⇒ Object
Sets the master seed.
-
#unlock! ⇒ false
Unlocks the configuration.
-
#unlocked? ⇒ Boolean
Checks if the configuration is unlocked.
Constructor Details
#initialize ⇒ Configuration
======================================================================
Instance Methods
======================================================================
87 88 89 90 91 92 93 |
# File 'lib/encoded_token/configuration.rb', line 87 def initialize @cipher_count = DEFAULT_CIPHER_COUNT @expiring_seeds = {} @locked = false @max_input_size = DEFAULT_MAX_INPUT_SIZE @min_token_size = DEFAULT_MIN_TOKEN_SIZE end |
Class Method Details
.instance ⇒ Configuration
Returns the singleton instance of the Configuration.
39 40 41 |
# File 'lib/encoded_token/configuration.rb', line 39 def instance @instance ||= new end |
.lock! ⇒ true
Locks the configuration to prevent further changes.
67 68 69 |
# File 'lib/encoded_token/configuration.rb', line 67 def lock! instance.lock! end |
.locked? ⇒ Boolean
Checks if the configuration is locked.
48 49 50 |
# File 'lib/encoded_token/configuration.rb', line 48 def locked? instance.locked? end |
.unlock! ⇒ false
Unlocks the configuration.
77 78 79 |
# File 'lib/encoded_token/configuration.rb', line 77 def unlock! instance.unlock! end |
.unlocked? ⇒ Boolean
Checks if the configuration is unlocked.
57 58 59 |
# File 'lib/encoded_token/configuration.rb', line 57 def unlocked? instance.unlocked? end |
Instance Method Details
#add_expiring_seed(expiring_seed, expiry_date, cipher_count = DEFAULT_CIPHER_COUNT) ⇒ Hash
Adds an expiring seed to the configuration.
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/encoded_token/configuration.rb', line 147 def add_expiring_seed(expiring_seed, expiry_date, cipher_count = DEFAULT_CIPHER_COUNT) assert_configuration_can_change! key = Integer(expiring_seed).abs rescue nil c_count = Integer(cipher_count).abs rescue nil if key && valid_date?(expiry_date) && valid_cipher_count?(c_count) @expiring_seeds[key] = {expires_on: expiry_date, cipher_count: c_count} else fail_with(:invalid_expiry_argument) end end |
#cipher_count ⇒ Integer
Returns the default cipher count.
165 166 167 |
# File 'lib/encoded_token/configuration.rb', line 165 def cipher_count @cipher_count end |
#cipher_count=(new_count) ⇒ Object
Sets the default cipher count.
178 179 180 181 182 183 184 185 |
# File 'lib/encoded_token/configuration.rb', line 178 def cipher_count=(new_count) assert_configuration_can_change! value = Integer(new_count).abs rescue nil fail_with(:invalid_cipher_count) unless valid_cipher_count?(value) @cipher_count = value end |
#expiring_seeds ⇒ Hash<Integer, Hash>
Returns the map of expiring seeds.
192 193 194 |
# File 'lib/encoded_token/configuration.rb', line 192 def expiring_seeds @expiring_seeds || {} end |
#lock! ⇒ true
Locks the configuration.
118 119 120 |
# File 'lib/encoded_token/configuration.rb', line 118 def lock! @locked = true end |
#locked? ⇒ Boolean
Checks if the configuration is locked.
100 101 102 |
# File 'lib/encoded_token/configuration.rb', line 100 def locked? !!@locked end |
#max_input_size ⇒ Integer
Returns the maximum input size.
201 202 203 |
# File 'lib/encoded_token/configuration.rb', line 201 def max_input_size @max_input_size end |
#max_input_size=(max_size) ⇒ Object
Sets the maximum input size.
213 214 215 216 217 218 219 220 |
# File 'lib/encoded_token/configuration.rb', line 213 def max_input_size=(max_size) assert_configuration_can_change! value = Integer(max_size).abs rescue nil fail_with(:invalid_max_input_size) if value.nil? || !value.positive? @max_input_size = value end |
#min_token_size ⇒ Integer
Returns the minimum token size.
227 228 229 |
# File 'lib/encoded_token/configuration.rb', line 227 def min_token_size @min_token_size end |
#min_token_size=(min_size) ⇒ Object
Sets the minimum token size.
239 240 241 242 243 244 245 246 |
# File 'lib/encoded_token/configuration.rb', line 239 def min_token_size=(min_size) assert_configuration_can_change! value = Integer(min_size).abs rescue nil fail_with(:invalid_min_token_size) if value.nil? || !value.positive? @min_token_size = value end |
#seed ⇒ Integer
Returns the master seed.
253 254 255 |
# File 'lib/encoded_token/configuration.rb', line 253 def seed @seed end |
#seed=(new_seed) ⇒ Object
Sets the master seed.
265 266 267 268 269 270 271 272 |
# File 'lib/encoded_token/configuration.rb', line 265 def seed=(new_seed) assert_configuration_can_change! value = Integer(new_seed).abs rescue nil fail_with(:invalid_seed) if value.nil? @seed = value end |
#unlock! ⇒ false
Unlocks the configuration.
127 128 129 |
# File 'lib/encoded_token/configuration.rb', line 127 def unlock! @locked = false end |
#unlocked? ⇒ Boolean
Checks if the configuration is unlocked.
109 110 111 |
# File 'lib/encoded_token/configuration.rb', line 109 def unlocked? !locked? end |