forked from ISS-Security/hw-credit_card_crypto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credit_card.rb
56 lines (48 loc) · 1.62 KB
/
credit_card.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require_relative './luhn_validator'
require 'json'
# Top level doc here :)
class CreditCard
# TODO: mixin the LuhnValidator using an 'include' statement
include LuhnValidator
# instance variables with automatic getter/setter methods
attr_accessor :number, :expiration_date, :owner, :credit_network
def initialize(number, expiration_date, owner, credit_network)
# TODO: initialize the instance variables listed above
@number = number
@expiration_date = expiration_date
@owner = owner
@credit_network = credit_network
end
# returns json string
def to_json(*_args)
{
# TODO: setup the hash with all instance vairables to serialize into json
'number' => @number,
'expiration_date' => @expiration_date,
'owner' => owner,
'credit_network' => credit_network
}.to_json
end
# returns all card information as single string
def to_s
to_json
end
# return a new CreditCard object given a serialized (JSON) representation
def self.from_s(card_s)
# TODO: deserializing a CreditCard object
end
# return a hash of the serialized credit card object
def hash
# TODO: implement this method
# - Produce a hash (using default hash method) of the credit card's
# serialized contents.
# - Credit cards with identical information should produce the same hash
end
# return a cryptographically secure hash
def hash_secure
# TODO: implement this method
# - Use sha256 from openssl to create a cryptographically secure hash.
# - Credit cards with identical information should produce the same hash
end
end