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 +4 -4
- data/lib/simple-hmac/helper.rb +5 -1
- data/lib/simple-hmac/version.rb +1 -1
- data/spec/hmac_token_spec.rb +16 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a4ec941a83001d8f89fe4746a10d2449640b5e7
|
4
|
+
data.tar.gz: 074b0922b331b34c3ad11a3ee30505bccc17e285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff761e4398581dff0c9cf941a86f7a99d94f741a27728bce6e6e47328e0c6ae3bbbaab42011f7bf652afeba203ff0507afe9491f94c7aee1767f67aa6c3fc561
|
7
|
+
data.tar.gz: f93ca40beaba7c202eb56dc40035a0ab5ae48d1709f06f86f1c862aee5e42bc5955d3c49b6352e6f2b9fbaa79fb6480e2dcc629b3cd3269114c86bad76ad9fd8
|
data/lib/simple-hmac/helper.rb
CHANGED
@@ -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
|
-
|
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={})
|
data/lib/simple-hmac/version.rb
CHANGED
data/spec/hmac_token_spec.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
RSpec.describe SimpleHmac::Helper do
|
2
2
|
context '#hmac_token' do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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 =
|
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 =
|
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.
|
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
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|