Class: Miasma::Contrib::AwsApiCore::Hmac
- Inherits:
-
Object
- Object
- Miasma::Contrib::AwsApiCore::Hmac
- Defined in:
- lib/miasma/contrib/aws.rb
Overview
HMAC helper class
Instance Attribute Summary collapse
- #digest ⇒ OpenSSL::Digest readonly
-
#key ⇒ String
readonly
Secret key.
Instance Method Summary collapse
-
#hex_sign(data, key_override = nil) ⇒ String
Sign the given data and return hexdigest.
-
#hexdigest_of(content) ⇒ String
Generate the hexdigest of the content.
-
#initialize(kind, key) ⇒ self
constructor
Create new HMAC helper.
-
#sign(data, key_override = nil) ⇒ Object
Sign the given data.
- #to_s ⇒ String
Constructor Details
#initialize(kind, key) ⇒ self
Create new HMAC helper
58 59 60 61 |
# File 'lib/miasma/contrib/aws.rb', line 58 def initialize(kind, key) @digest = OpenSSL::Digest.new(kind) @key = key end |
Instance Attribute Details
#digest ⇒ OpenSSL::Digest (readonly)
49 50 51 |
# File 'lib/miasma/contrib/aws.rb', line 49 def digest @digest end |
#key ⇒ String (readonly)
Returns secret key.
51 52 53 |
# File 'lib/miasma/contrib/aws.rb', line 51 def key @key end |
Instance Method Details
#hex_sign(data, key_override = nil) ⇒ String
Sign the given data and return hexdigest
95 96 97 98 99 |
# File 'lib/miasma/contrib/aws.rb', line 95 def hex_sign(data, key_override=nil) result = OpenSSL::HMAC.hexdigest(digest, key_override || key, data) digest.reset result end |
#hexdigest_of(content) ⇒ String
Generate the hexdigest of the content
72 73 74 75 76 77 |
# File 'lib/miasma/contrib/aws.rb', line 72 def hexdigest_of(content) digest << content hash = digest.hexdigest digest.reset hash end |
#sign(data, key_override = nil) ⇒ Object
Sign the given data
84 85 86 87 88 |
# File 'lib/miasma/contrib/aws.rb', line 84 def sign(data, key_override=nil) result = OpenSSL::HMAC.digest(digest, key_override || key, data) digest.reset result end |
#to_s ⇒ String
64 65 66 |
# File 'lib/miasma/contrib/aws.rb', line 64 def to_s "Hmac#{digest.name}" end |