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.
@@ -1,3 +1,9 @@
1
+ == 0.4.0 / 2010-01-19
2
+
3
+ * Ruby 1.9 compatibility [Tim Kersey]
4
+ * Minitest integration [Tim Kersey]
5
+ * Updated to Hoe 2.5.0 [Geoffrey Grosenbach]
6
+
1
7
  == 0.3.2 / 2008-08-20
2
8
 
3
9
  * Removed spurious constants that cause warnings on load [Blaine Cook]
@@ -7,4 +7,5 @@ lib/hmac-rmd160.rb
7
7
  lib/hmac-sha1.rb
8
8
  lib/hmac-sha2.rb
9
9
  lib/hmac.rb
10
+ lib/ruby_hmac.rb
10
11
  test/test_hmac.rb
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
- ruby-hmac
2
- by Daiki Ueno
3
- http://ruby-hmac.rubyforge.org
1
+ = ruby-hmac
2
+
3
+ * http://ruby-hmac.rubyforge.org
4
4
 
5
5
  == DESCRIPTION:
6
6
 
data/Rakefile CHANGED
@@ -3,17 +3,15 @@ require 'hoe'
3
3
  $:.unshift(File.dirname(__FILE__) + "/lib")
4
4
  require 'hmac'
5
5
 
6
- Hoe.new('ruby-hmac', HMAC::VERSION) do |p|
7
- p.name = "ruby-hmac"
8
- p.author = ["Daiki Ueno", "Geoffrey Grosenbach"]
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
@@ -17,7 +17,7 @@
17
17
 
18
18
  module HMAC
19
19
 
20
- VERSION = '0.3.2'
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
- key_xor_ipad = "\x36" * @block_size
47
- key_xor_opad = "\x5C" * @block_size
48
- for i in 0 .. key.size - 1
49
- key_xor_ipad[i] ^= key[i]
50
- key_xor_opad[i] ^= key[i]
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
@@ -0,0 +1,2 @@
1
+ # Convenience file to match gem name
2
+ require 'hmac'
@@ -1,11 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
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
- require 'hmac-md5'
6
- require 'hmac-sha1'
13
+ MiniTest::Unit.autorun
7
14
 
8
- class TestHMAC < Test::Unit::TestCase
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
- "9294727a3638bb1c13f48ef8158bfc9d")
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
- "750c783e6ab0b503eaa86e310a5db738")
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
- "56be34521d144c88dbb8c733f0e8b3f6")
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
- "697eaf0aca3a3aea3a75164746ffaa79")
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
- "56461ef2342edc00f9bab995690efd4c")
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
- # "56461ef2342edc00f9bab995")
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
- "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd")
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
- "6f630fad67cda0ee1fb1f562db3aa53e")
74
+ "6f630fad67cda0ee1fb1f562db3aa53e")
68
75
  end
69
76
 
70
77
  def test_reset_key
71
78
  hmac = HMAC::MD5.new("key")
72
- assert_nothing_raised {
73
- hmac.reset_key
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
- assert_raise(RuntimeError) {
83
- hmac.update("foo")
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.3.2
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: 2008-08-21 00:00:00 -07:00
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: 1.7.0
44
+ version: 2.5.0
25
45
  version:
26
- 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.
27
- email: boss@topfunky.com
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.2.0
98
+ rubygems_version: 1.3.5
71
99
  signing_key:
72
- specification_version: 2
73
- summary: An implementation of the HMAC authentication code in Ruby.
100
+ specification_version: 3
101
+ summary: This module provides common interface to HMAC functionality
74
102
  test_files:
75
103
  - test/test_hmac.rb