Skip to content

Commit d62ecf8

Browse files
Expose the default costs used through constants (#57)
This allows third-party libraries to inspect those values and use them.
1 parent 8d2c132 commit d62ecf8

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

lib/argon2.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010
module Argon2
1111
# Front-end API for the Argon2 module.
1212
class Password
13+
# Expose constants for the options supported and default used for passwords.
14+
DEFAULT_T_COST = 2
15+
DEFAULT_M_COST = 16
16+
DEFAULT_P_COST = 1
17+
MIN_T_COST = 1
18+
MAX_T_COST = 750
19+
MIN_M_COST = 1
20+
MAX_M_COST = 31
21+
MIN_P_COST = 1
22+
MAX_P_COST = 8
23+
1324
def initialize(options = {})
14-
@t_cost = options[:t_cost] || 2
15-
raise ArgonHashFail, "Invalid t_cost" if @t_cost < 1 || @t_cost > 750
25+
@t_cost = options[:t_cost] || DEFAULT_T_COST
26+
raise ArgonHashFail, "Invalid t_cost" if @t_cost < MIN_T_COST || @t_cost > MAX_T_COST
1627

17-
@m_cost = options[:m_cost] || 16
18-
raise ArgonHashFail, "Invalid m_cost" if @m_cost < 1 || @m_cost > 31
28+
@m_cost = options[:m_cost] || DEFAULT_M_COST
29+
raise ArgonHashFail, "Invalid m_cost" if @m_cost < MIN_M_COST || @m_cost > MAX_M_COST
1930

20-
@p_cost = options[:p_cost] || 1
21-
raise ArgonHashFail, "Invalid p_cost" if @p_cost < 1 || @p_cost > 8
31+
@p_cost = options[:p_cost] || DEFAULT_P_COST
32+
raise ArgonHashFail, "Invalid p_cost" if @p_cost < MIN_P_COST || @p_cost > MAX_P_COST
2233

2334
@salt_do_not_supply = options[:salt_do_not_supply]
2435
@secret = options[:secret]

0 commit comments

Comments
 (0)