class Argon2::HashFormat

def initialize(digest)

rubocop:disable Metrics/AbcSize
FIXME: Reduce complexity/AbcSize
def initialize(digest)
  digest = digest.to_s unless digest.is_a?(String)
  raise Argon2::ArgonHashFail, 'Invalid Argon2 hash' unless self.class.valid_hash?(digest)
  _, variant, version, config, salt, checksum = digest.split('$')
  # Regex magic to extract the values for each setting
  version = /v=(\d+)/.match(version)
  t_cost  = /t=(\d+),/.match(config)
  m_cost  = /m=(\d+),/.match(config)
  p_cost  = /p=(\d+)/.match(config)
  # Make sure none of the values are missing
  raise Argon2::ArgonHashFail, 'Invalid Argon2 version' if version.nil?
  raise Argon2::ArgonHashFail, 'Invalid Argon2 time cost' if t_cost.nil?
  raise Argon2::ArgonHashFail, 'Invalid Argon2 memory cost' if m_cost.nil?
  raise Argon2::ArgonHashFail, 'Invalid Argon2 parallelism cost' if p_cost.nil?
  @variant  = variant.to_str
  @version  = version[1].to_i
  @t_cost   = t_cost[1].to_i
  @m_cost   = m_cost[1].to_i
  @p_cost   = p_cost[1].to_i
  @salt     = salt.to_str
  @checksum = checksum.to_str
end