Class: Altcha::V2::ChallengeParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/altcha/v2.rb

Overview

All parameters embedded in a v2 challenge.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm:, nonce:, salt:, cost:, key_length: DEFAULT_KEY_LENGTH, key_prefix: DEFAULT_KEY_PREFIX, key_signature: nil, memory_cost: nil, parallelism: nil, expires_at: nil, data: nil) ⇒ ChallengeParameters

Returns a new instance of ChallengeParameters.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/altcha/v2.rb', line 21

def initialize(algorithm:, nonce:, salt:, cost:, key_length: DEFAULT_KEY_LENGTH,
               key_prefix: DEFAULT_KEY_PREFIX, key_signature: nil,
               memory_cost: nil, parallelism: nil, expires_at: nil, data: nil)
  @algorithm    = algorithm
  @nonce        = nonce
  @salt         = salt
  @cost         = cost
  @key_length   = key_length
  @key_prefix   = key_prefix
  @key_signature = key_signature
  @memory_cost  = memory_cost
  @parallelism  = parallelism
  @expires_at   = expires_at
  @data         = data
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def algorithm
  @algorithm
end

#costObject

Returns the value of attribute cost.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def cost
  @cost
end

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def data
  @data
end

#expires_atObject

Returns the value of attribute expires_at.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def expires_at
  @expires_at
end

#key_lengthObject

Returns the value of attribute key_length.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def key_length
  @key_length
end

#key_prefixObject

Returns the value of attribute key_prefix.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def key_prefix
  @key_prefix
end

#key_signatureObject

Returns the value of attribute key_signature.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def key_signature
  @key_signature
end

#memory_costObject

Returns the value of attribute memory_cost.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def memory_cost
  @memory_cost
end

#nonceObject

Returns the value of attribute nonce.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def nonce
  @nonce
end

#parallelismObject

Returns the value of attribute parallelism.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def parallelism
  @parallelism
end

#saltObject

Returns the value of attribute salt.



18
19
20
# File 'lib/altcha/v2.rb', line 18

def salt
  @salt
end

Instance Method Details

#to_hObject

Serializes to a plain Hash with camelCase keys, omitting nil optional fields. The resulting hash must be stable across round-trips for HMAC signing to work.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/altcha/v2.rb', line 39

def to_h
  h = {
    'algorithm' => algorithm,
    'cost'      => cost,
    'keyLength' => key_length,
    'keyPrefix' => key_prefix,
    'nonce'     => nonce,
    'salt'      => salt,
  }
  h['data']         = data          unless data.nil?
  h['expiresAt']    = expires_at    unless expires_at.nil?
  h['keySignature'] = key_signature unless key_signature.nil?
  h['memoryCost']   = memory_cost   unless memory_cost.nil?
  h['parallelism']  = parallelism   unless parallelism.nil?
  h
end

#to_json(options = {}) ⇒ Object



56
57
58
# File 'lib/altcha/v2.rb', line 56

def to_json(options = {})
  to_h.to_json(options)
end