ruby-hmac 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +3 -5
- data/Rakefile +10 -0
- data/lib/hmac.rb +23 -21
- data/test/test_hmac.rb +0 -0
- metadata +55 -49
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -13,3 +13,13 @@ Hoe.new('ruby-hmac', HMAC::VERSION) do |p|
|
|
13
13
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
14
14
|
p.remote_rdoc_dir = '' # Release to root
|
15
15
|
end
|
16
|
+
|
17
|
+
desc "Simple require on packaged files to make sure they are all there"
|
18
|
+
task :verify => :package do
|
19
|
+
# An error message will be displayed if files are missing
|
20
|
+
if system %(ruby -e "require 'pkg/ruby-hmac-#{HMAC::VERSION}/lib/hmac'")
|
21
|
+
puts "\nThe library files are present"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
task :release => :verify
|
data/lib/hmac.rb
CHANGED
@@ -10,17 +10,21 @@
|
|
10
10
|
# These APIs are inspired by JCE 1.2's javax.crypto.Mac interface.
|
11
11
|
#
|
12
12
|
# <URL:http://java.sun.com/security/JCE1.2/spec/apidoc/javax/crypto/Mac.html>
|
13
|
+
#
|
14
|
+
# Source repository is at
|
15
|
+
#
|
16
|
+
# http://github.com/topfunky/ruby-hmac/tree/master
|
13
17
|
|
14
18
|
module HMAC
|
15
|
-
|
16
|
-
VERSION = '0.3.
|
17
|
-
|
19
|
+
|
20
|
+
VERSION = '0.3.2'
|
21
|
+
|
18
22
|
class Base
|
19
23
|
def initialize(algorithm, block_size, output_length, key)
|
20
24
|
@algorithm = algorithm
|
21
25
|
@block_size = block_size
|
22
26
|
@output_length = output_length
|
23
|
-
@
|
27
|
+
@initialized = false
|
24
28
|
@key_xor_ipad = ''
|
25
29
|
@key_xor_opad = ''
|
26
30
|
set_key(key) unless key.nil?
|
@@ -28,9 +32,9 @@ module HMAC
|
|
28
32
|
|
29
33
|
private
|
30
34
|
def check_status
|
31
|
-
unless @
|
32
|
-
|
33
|
-
|
35
|
+
unless @initialized
|
36
|
+
raise RuntimeError,
|
37
|
+
"The underlying hash algorithm has not yet been initialized."
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
@@ -42,13 +46,13 @@ module HMAC
|
|
42
46
|
key_xor_ipad = "\x36" * @block_size
|
43
47
|
key_xor_opad = "\x5C" * @block_size
|
44
48
|
for i in 0 .. key.size - 1
|
45
|
-
|
46
|
-
|
49
|
+
key_xor_ipad[i] ^= key[i]
|
50
|
+
key_xor_opad[i] ^= key[i]
|
47
51
|
end
|
48
52
|
@key_xor_ipad = key_xor_ipad
|
49
53
|
@key_xor_opad = key_xor_opad
|
50
54
|
@md = @algorithm.new
|
51
|
-
@
|
55
|
+
@initialized = true
|
52
56
|
end
|
53
57
|
|
54
58
|
def reset_key
|
@@ -56,7 +60,7 @@ module HMAC
|
|
56
60
|
@key_xor_opad.gsub!(/./, '?')
|
57
61
|
@key_xor_ipad[0..-1] = ''
|
58
62
|
@key_xor_opad[0..-1] = ''
|
59
|
-
@
|
63
|
+
@initialized = false
|
60
64
|
end
|
61
65
|
|
62
66
|
def update(text)
|
@@ -90,26 +94,24 @@ module HMAC
|
|
90
94
|
# held a key even if it's no longer in use.
|
91
95
|
def Base.digest(key, text)
|
92
96
|
begin
|
93
|
-
|
94
|
-
|
95
|
-
|
97
|
+
hmac = self.new(key)
|
98
|
+
hmac.update(text)
|
99
|
+
hmac.digest
|
96
100
|
ensure
|
97
|
-
|
101
|
+
hmac.reset_key
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
105
|
def Base.hexdigest(key, text)
|
102
106
|
begin
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
hmac = self.new(key)
|
108
|
+
hmac.update(text)
|
109
|
+
hmac.hexdigest
|
106
110
|
ensure
|
107
|
-
|
111
|
+
hmac.reset_key
|
108
112
|
end
|
109
113
|
end
|
110
114
|
|
111
115
|
private_class_method :new, :digest, :hexdigest
|
112
116
|
end
|
113
|
-
|
114
|
-
STATUS_UNDEFINED, STATUS_INITIALIZED = 0, 1
|
115
117
|
end
|
data/test/test_hmac.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,69 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: ruby-hmac
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2007-08-13 00:00:00 -07:00
|
8
|
-
summary: An implementation of the HMAC authentication code in Ruby.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: boss@topfunky.com
|
12
|
-
homepage: http://ruby-hmac.rubyforge.org
|
13
|
-
rubyforge_project: ruby-hmac
|
14
|
-
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.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.3.2
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daiki Ueno
|
31
8
|
- Geoffrey Grosenbach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-08-21 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: hoe
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.7.0
|
25
|
+
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
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
32
36
|
files:
|
33
37
|
- History.txt
|
34
|
-
-
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
35
41
|
- lib/hmac-md5.rb
|
36
42
|
- lib/hmac-rmd160.rb
|
37
43
|
- lib/hmac-sha1.rb
|
38
44
|
- lib/hmac-sha2.rb
|
39
45
|
- lib/hmac.rb
|
40
|
-
- Manifest.txt
|
41
|
-
- Rakefile
|
42
|
-
- README.txt
|
43
|
-
- test/
|
44
|
-
- test/test_hmac.rb
|
45
|
-
test_files:
|
46
46
|
- test/test_hmac.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://ruby-hmac.rubyforge.org
|
49
|
+
post_install_message:
|
47
50
|
rdoc_options:
|
48
51
|
- --main
|
49
52
|
- README.txt
|
50
|
-
|
51
|
-
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
58
67
|
requirements: []
|
59
68
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.2.2
|
69
|
-
version:
|
69
|
+
rubyforge_project: ruby-hmac
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: An implementation of the HMAC authentication code in Ruby.
|
74
|
+
test_files:
|
75
|
+
- test/test_hmac.rb
|