ruby-hmac 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/README.txt +3 -3
- data/Rakefile +7 -9
- data/lib/hmac.rb +11 -10
- data/lib/ruby_hmac.rb +2 -0
- data/test/test_hmac.rb +29 -32
- metadata +36 -8
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -3,17 +3,15 @@ require 'hoe'
|
|
3
3
|
$:.unshift(File.dirname(__FILE__) + "/lib")
|
4
4
|
require 'hmac'
|
5
5
|
|
6
|
-
Hoe.
|
7
|
-
|
8
|
-
|
9
|
-
p.email = 'boss@topfunky.com'
|
10
|
-
p.summary = "An implementation of the HMAC authentication code in Ruby."
|
11
|
-
p.description = "A MAC provides a way to check the integrity of information transmitted over or stored in an unreliable medium, based on a secret key."
|
12
|
-
p.url = "http://ruby-hmac.rubyforge.org"
|
13
|
-
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
14
|
-
p.remote_rdoc_dir = '' # Release to root
|
6
|
+
Hoe.spec 'ruby-hmac' do
|
7
|
+
developer "Daiki Ueno", ""
|
8
|
+
developer "Geoffrey Grosenbach", "boss@topfunky.com"
|
15
9
|
end
|
16
10
|
|
11
|
+
Hoe.plugin :minitest
|
12
|
+
Hoe.plugin :git
|
13
|
+
Hoe.plugin :gemcutter
|
14
|
+
|
17
15
|
desc "Simple require on packaged files to make sure they are all there"
|
18
16
|
task :verify => :package do
|
19
17
|
# An error message will be displayed if files are missing
|
data/lib/hmac.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
module HMAC
|
19
19
|
|
20
|
-
VERSION = '0.
|
20
|
+
VERSION = '0.4.0'
|
21
21
|
|
22
22
|
class Base
|
23
23
|
def initialize(algorithm, block_size, output_length, key)
|
@@ -43,14 +43,15 @@ module HMAC
|
|
43
43
|
# If key is longer than the block size, apply hash function
|
44
44
|
# to key and use the result as a real key.
|
45
45
|
key = @algorithm.digest(key) if key.size > @block_size
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
akey = key.unpack("C*")
|
47
|
+
key_xor_ipad = ("\x36" * @block_size).unpack("C*")
|
48
|
+
key_xor_opad = ("\x5C" * @block_size).unpack("C*")
|
49
|
+
for i in 0 .. akey.size - 1
|
50
|
+
key_xor_ipad[i] ^= akey[i]
|
51
|
+
key_xor_opad[i] ^= akey[i]
|
51
52
|
end
|
52
|
-
@key_xor_ipad = key_xor_ipad
|
53
|
-
@key_xor_opad = key_xor_opad
|
53
|
+
@key_xor_ipad = key_xor_ipad.pack("C*")
|
54
|
+
@key_xor_opad = key_xor_opad.pack("C*")
|
54
55
|
@md = @algorithm.new
|
55
56
|
@initialized = true
|
56
57
|
end
|
@@ -93,8 +94,8 @@ module HMAC
|
|
93
94
|
# instance methods combinatorially because an instance will have
|
94
95
|
# held a key even if it's no longer in use.
|
95
96
|
def Base.digest(key, text)
|
97
|
+
hmac = self.new(key)
|
96
98
|
begin
|
97
|
-
hmac = self.new(key)
|
98
99
|
hmac.update(text)
|
99
100
|
hmac.digest
|
100
101
|
ensure
|
@@ -103,8 +104,8 @@ module HMAC
|
|
103
104
|
end
|
104
105
|
|
105
106
|
def Base.hexdigest(key, text)
|
107
|
+
hmac = self.new(key)
|
106
108
|
begin
|
107
|
-
hmac = self.new(key)
|
108
109
|
hmac.update(text)
|
109
110
|
hmac.hexdigest
|
110
111
|
ensure
|
data/lib/ruby_hmac.rb
ADDED
data/test/test_hmac.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
4
|
+
require "hmac-md5"
|
5
|
+
require "hmac-sha1"
|
6
|
+
begin
|
7
|
+
require "minitest/unit"
|
8
|
+
rescue LoadError
|
9
|
+
require "rubygems"
|
10
|
+
require "minitest/unit"
|
11
|
+
end
|
4
12
|
|
5
|
-
|
6
|
-
require 'hmac-sha1'
|
13
|
+
MiniTest::Unit.autorun
|
7
14
|
|
8
|
-
class
|
15
|
+
class TestHmac < MiniTest::Unit::TestCase
|
9
16
|
|
10
17
|
def test_s_digest
|
11
18
|
key = "\x0b" * 16
|
@@ -13,7 +20,7 @@ class TestHMAC < Test::Unit::TestCase
|
|
13
20
|
|
14
21
|
hmac = HMAC::MD5.new(key)
|
15
22
|
hmac.update(text)
|
16
|
-
|
23
|
+
|
17
24
|
assert_equal(hmac.digest, HMAC::MD5.digest(key, text))
|
18
25
|
end
|
19
26
|
|
@@ -23,70 +30,60 @@ class TestHMAC < Test::Unit::TestCase
|
|
23
30
|
|
24
31
|
hmac = HMAC::MD5.new(key)
|
25
32
|
hmac.update(text)
|
26
|
-
|
33
|
+
|
27
34
|
assert_equal(hmac.hexdigest, HMAC::MD5.hexdigest(key, text))
|
28
35
|
end
|
29
36
|
|
30
37
|
def test_hmac_md5_1
|
31
38
|
assert_equal(HMAC::MD5.hexdigest("\x0b" * 16, "Hi There"),
|
32
|
-
|
39
|
+
"9294727a3638bb1c13f48ef8158bfc9d")
|
33
40
|
end
|
34
41
|
|
35
42
|
def test_hmac_md5_2
|
36
43
|
assert_equal(HMAC::MD5.hexdigest("Jefe", "what do ya want for nothing?"),
|
37
|
-
|
44
|
+
"750c783e6ab0b503eaa86e310a5db738")
|
38
45
|
end
|
39
46
|
|
40
47
|
def test_hmac_md5_3
|
41
48
|
assert_equal(HMAC::MD5.hexdigest("\xaa" * 16, "\xdd" * 50),
|
42
|
-
|
49
|
+
"56be34521d144c88dbb8c733f0e8b3f6")
|
43
50
|
end
|
44
51
|
|
45
52
|
def test_hmac_md5_4
|
46
53
|
assert_equal(HMAC::MD5.hexdigest(["0102030405060708090a0b0c0d0e0f10111213141516171819"].pack("H*"), "\xcd" * 50),
|
47
|
-
|
54
|
+
"697eaf0aca3a3aea3a75164746ffaa79")
|
48
55
|
end
|
49
56
|
|
50
57
|
def test_hmac_md5_5
|
51
58
|
assert_equal(HMAC::MD5.hexdigest("\x0c" * 16, "Test With Truncation"),
|
52
|
-
|
59
|
+
"56461ef2342edc00f9bab995690efd4c")
|
53
60
|
end
|
54
61
|
|
55
|
-
# def test_hmac_md5_6
|
56
|
-
# assert_equal(HMAC::MD5.hexdigest("\x0c" * 16, "Test With Truncation"),
|
57
|
-
#
|
58
|
-
# end
|
62
|
+
# def test_hmac_md5_6
|
63
|
+
# assert_equal(HMAC::MD5.hexdigest("\x0c" * 16, "Test With Truncation"),
|
64
|
+
# "56461ef2342edc00f9bab995")
|
65
|
+
# end
|
59
66
|
|
60
67
|
def test_hmac_md5_7
|
61
68
|
assert_equal(HMAC::MD5.hexdigest("\xaa" * 80, "Test Using Larger Than Block-Size Key - Hash Key First"),
|
62
|
-
|
69
|
+
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd")
|
63
70
|
end
|
64
71
|
|
65
72
|
def test_hmac_md5_8
|
66
73
|
assert_equal(HMAC::MD5.hexdigest("\xaa" * 80, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"),
|
67
|
-
|
74
|
+
"6f630fad67cda0ee1fb1f562db3aa53e")
|
68
75
|
end
|
69
76
|
|
70
77
|
def test_reset_key
|
71
78
|
hmac = HMAC::MD5.new("key")
|
72
|
-
|
73
|
-
|
74
|
-
}
|
75
|
-
assert_raise(RuntimeError) {
|
76
|
-
hmac.update("foo")
|
77
|
-
}
|
79
|
+
hmac.reset_key
|
80
|
+
assert_raises(RuntimeError) { hmac.update("foo") }
|
78
81
|
end
|
79
82
|
|
80
83
|
def test_set_key
|
81
84
|
hmac = HMAC::MD5.new
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
assert_nothing_raised {
|
86
|
-
hmac.reset_key
|
87
|
-
}
|
88
|
-
assert_raise(RuntimeError) {
|
89
|
-
hmac.update("foo")
|
90
|
-
}
|
85
|
+
assert_raises(RuntimeError) { hmac.update("foo") }
|
86
|
+
hmac.reset_key
|
87
|
+
assert_raises(RuntimeError) { hmac.update("foo") }
|
91
88
|
end
|
92
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daiki Ueno
|
@@ -10,9 +10,29 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2010-01-20 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rubyforge
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.3
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: gemcutter
|
28
|
+
type: :development
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.2.1
|
35
|
+
version:
|
16
36
|
- !ruby/object:Gem::Dependency
|
17
37
|
name: hoe
|
18
38
|
type: :development
|
@@ -21,10 +41,15 @@ dependencies:
|
|
21
41
|
requirements:
|
22
42
|
- - ">="
|
23
43
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
44
|
+
version: 2.5.0
|
25
45
|
version:
|
26
|
-
description:
|
27
|
-
|
46
|
+
description: |-
|
47
|
+
This module provides common interface to HMAC functionality. HMAC is a kind of "Message Authentication Code" (MAC) algorithm whose standard is documented in RFC2104. Namely, a MAC provides a way to check the integrity of information transmitted over or stored in an unreliable medium, based on a secret key.
|
48
|
+
|
49
|
+
Originally written by Daiki Ueno. Converted to a RubyGem by Geoffrey Grosenbach
|
50
|
+
email:
|
51
|
+
- ""
|
52
|
+
- boss@topfunky.com
|
28
53
|
executables: []
|
29
54
|
|
30
55
|
extensions: []
|
@@ -43,9 +68,12 @@ files:
|
|
43
68
|
- lib/hmac-sha1.rb
|
44
69
|
- lib/hmac-sha2.rb
|
45
70
|
- lib/hmac.rb
|
71
|
+
- lib/ruby_hmac.rb
|
46
72
|
- test/test_hmac.rb
|
47
73
|
has_rdoc: true
|
48
74
|
homepage: http://ruby-hmac.rubyforge.org
|
75
|
+
licenses: []
|
76
|
+
|
49
77
|
post_install_message:
|
50
78
|
rdoc_options:
|
51
79
|
- --main
|
@@ -67,9 +95,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
95
|
requirements: []
|
68
96
|
|
69
97
|
rubyforge_project: ruby-hmac
|
70
|
-
rubygems_version: 1.
|
98
|
+
rubygems_version: 1.3.5
|
71
99
|
signing_key:
|
72
|
-
specification_version:
|
73
|
-
summary:
|
100
|
+
specification_version: 3
|
101
|
+
summary: This module provides common interface to HMAC functionality
|
74
102
|
test_files:
|
75
103
|
- test/test_hmac.rb
|