Skip to content

Commit

Permalink
Add Response class as base
Browse files Browse the repository at this point in the history
  • Loading branch information
aldosolorzano committed Nov 20, 2018
1 parent 889da9f commit 1fef832
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/crypto.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Crypto
autoload :PBE, 'crypto/pbe'
autoload :Response, 'crypto/response'
end
11 changes: 2 additions & 9 deletions lib/crypto/pbe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,12 @@ def derived_key(password, salt, sizeKey = 24)
end
end

class PKCS5
class PKCS5 < Crypto::Response
attr_reader :key

def ==(other)
key == other.key
end

def initialize(args)
@key = OpenSSL::PKCS5.pbkdf2_hmac(*args.values)
end

def to_hex
key.unpack('H*').first
@data = key # key attribute is syntax sugar
end
end
end
17 changes: 17 additions & 0 deletions lib/crypto/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Crypto
class Response
attr_reader :data

def ==(other)
data == other.data
end

def initialize(data)
@data = data
end

def to_hex
data.unpack('H*').first
end
end
end

0 comments on commit 1fef832

Please sign in to comment.