simple-hmac 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8df9b536189c550e347e8957860c825671827340
4
- data.tar.gz: b212b86247013ebfa722bacebf794e933bb02cac
3
+ metadata.gz: 9a4ec941a83001d8f89fe4746a10d2449640b5e7
4
+ data.tar.gz: 074b0922b331b34c3ad11a3ee30505bccc17e285
5
5
  SHA512:
6
- metadata.gz: 50544713054a17897ca7bc22e390485adf670acec661bf774adc9fd64ad07e34a1f5c43ed3318d2ddaaa5b3e6012b6db5e3a5253ad90690371837ef809e28589
7
- data.tar.gz: 54677f8d988498a8fbac9b92dde9724ba26c43c9715440f2adfae7bed991363052c73936fb127eaf65d816857fcb3e2e83443a06d2165275952acb3de2ac4db4
6
+ metadata.gz: ff761e4398581dff0c9cf941a86f7a99d94f741a27728bce6e6e47328e0c6ae3bbbaab42011f7bf652afeba203ff0507afe9491f94c7aee1767f67aa6c3fc561
7
+ data.tar.gz: f93ca40beaba7c202eb56dc40035a0ab5ae48d1709f06f86f1c862aee5e42bc5955d3c49b6352e6f2b9fbaa79fb6480e2dcc629b3cd3269114c86bad76ad9fd8
@@ -11,7 +11,11 @@ module SimpleHmac
11
11
  data = [verb.upcase, content_type, content_md5, url_without_server, date]
12
12
  data.shift unless options[:include_verb]
13
13
  string_to_sign = data.join(options[:separator])
14
- Base64.strict_encode64(OpenSSL::HMAC.digest(options[:algorithm], api_secret, string_to_sign))
14
+ sign_string(string_to_sign, api_secret, options[:algorithm])
15
+ end
16
+
17
+ def sign_string(string, secret, algorithm = 'sha256')
18
+ Base64.strict_encode64(OpenSSL::HMAC.digest(algorithm, secret, string))
15
19
  end
16
20
 
17
21
  def authentication_headers(verb, content_type, payload, url, api_key, api_secret, options={})
@@ -1,3 +1,3 @@
1
1
  module SimpleHmac
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -1,16 +1,25 @@
1
1
  RSpec.describe SimpleHmac::Helper do
2
2
  context '#hmac_token' do
3
- before do
4
- @signer = Object.new
5
- @signer.extend SimpleHmac::Helper
6
- end
3
+ let(:secret) { 'SECRET CODE' }
4
+
5
+ let(:signer) { Object.new.tap { |o| o.extend SimpleHmac::Helper } }
6
+
7
7
  it 'should use default values for GET' do
8
- actual = @signer.hmac_token(:get, 'application/json', '', 'http://example.com/hello', 'Mon, 16 Feb 2015 11:06:40 GMT', 'SECRET_CODE')
8
+ actual = signer.hmac_token(:get, 'application/json', '', 'http://example.com/hello', 'Mon, 16 Feb 2015 11:06:40 GMT', secret)
9
9
 
10
10
  string_to_sign = ['GET', 'application/json', '', '/hello', 'Mon, 16 Feb 2015 11:06:40 GMT'].join("\n")
11
- expected = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', 'SECRET_CODE', string_to_sign))
11
+ expected = signer.sign_string(string_to_sign, secret)
12
12
 
13
13
  expect(actual).to eq(expected)
14
14
  end
15
+
16
+ describe '#sign_string' do
17
+ it 'is the base64 encoded HMAC' do
18
+ string = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
19
+ expected = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', secret, string))
20
+ actual = signer.sign_string(string, secret, 'sha256')
21
+ expect(actual).to eq expected
22
+ end
23
+ end
15
24
  end
16
- end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-hmac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chaker Nakhli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client