cipher 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/cipher.gemspec +2 -2
- data/lib/cipher/generator.rb +16 -9
- data/lib/cipher/validator.rb +8 -1
- data/test/test_cipher.rb +20 -2
- metadata +21 -21
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
17
|
gem.name = "cipher"
|
18
|
-
gem.homepage = "http://github.com/
|
18
|
+
gem.homepage = "http://github.com/massivedanger/cipher"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{Generate and validate license keys}
|
21
21
|
gem.description = %Q{Generate and validate license keys}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/cipher.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cipher"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Evan Walsh"]
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"test/helper.rb",
|
34
34
|
"test/test_cipher.rb"
|
35
35
|
]
|
36
|
-
s.homepage = "http://github.com/
|
36
|
+
s.homepage = "http://github.com/massivedanger/cipher"
|
37
37
|
s.licenses = ["MIT"]
|
38
38
|
s.require_paths = ["lib"]
|
39
39
|
s.rubygems_version = "1.8.10"
|
data/lib/cipher/generator.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
-
class Cipher
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class Cipher
|
2
|
+
module Generator
|
3
|
+
def generate(args = {})
|
4
|
+
@key_length ||= args[:key_length]
|
5
|
+
@section_length ||= args[:section_length]
|
6
|
+
@seperator ||= args[:seperator]
|
7
|
+
unique = args[:unique]
|
8
|
+
|
6
9
|
output = ''
|
7
10
|
i = 0
|
8
11
|
|
12
|
+
if unique.nil?
|
13
|
+
raise ArgumentError, 'You need to pass a hash with a unique to generate a key'
|
14
|
+
end
|
15
|
+
|
9
16
|
while i < (@key_length/@section_length).ceil do
|
10
17
|
output << hash(unique + i.to_s)[0..@section_length-1] + @seperator
|
11
18
|
i += 1
|
@@ -15,6 +22,8 @@ class Cipher
|
|
15
22
|
end
|
16
23
|
|
17
24
|
def hash(string)
|
25
|
+
@hasher ||= 'sha1'
|
26
|
+
|
18
27
|
case @hasher
|
19
28
|
when 'sha1'
|
20
29
|
require 'digest/sha1'
|
@@ -27,8 +36,6 @@ class Cipher
|
|
27
36
|
Digest::SHA1.hexdigest(string)
|
28
37
|
end
|
29
38
|
end
|
30
|
-
private :hash
|
31
|
-
|
32
|
-
end
|
33
|
-
|
39
|
+
private :hash
|
40
|
+
end
|
34
41
|
end
|
data/lib/cipher/validator.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
class Cipher
|
2
2
|
module Validator
|
3
3
|
def validate(args = {})
|
4
|
-
|
4
|
+
unique = args[:unique]
|
5
|
+
key = args[:key]
|
6
|
+
|
7
|
+
if unique.nil? || key.nil?
|
8
|
+
raise ArgumentError, 'You need to pass a hash with a unique string and a key to validate'
|
9
|
+
end
|
10
|
+
|
11
|
+
generate({ unique: unique }) == key
|
5
12
|
end
|
6
13
|
end
|
7
14
|
end
|
data/test/test_cipher.rb
CHANGED
@@ -11,10 +11,28 @@ class TestCipher < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
should 'generate a key' do
|
14
|
-
assert_instance_of String, @cipher.generate
|
14
|
+
assert_instance_of String, @cipher.generate({ unique: 'Evan Walsh' })
|
15
15
|
end
|
16
16
|
|
17
17
|
should 'validate a key' do
|
18
|
-
assert @cipher.validate(@cipher.generate)
|
18
|
+
assert @cipher.validate({ unique: 'Evan Walsh', key: @cipher.generate({ unique: 'Evan Walsh' }) })
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'raise ArgumentError if non-unique generation is done' do
|
22
|
+
assert_raises ArgumentError do
|
23
|
+
@cipher.generate
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'raise ArgumentError if non-unique validation is done' do
|
28
|
+
assert_raises ArgumentError do
|
29
|
+
@cipher.validate
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'get rid of the end seperator' do
|
34
|
+
key = @cipher.generate({ unique: 'Evan Walsh' })
|
35
|
+
|
36
|
+
assert key[-1] != @cipher.seperator[-1]
|
19
37
|
end
|
20
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cipher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-27 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &70123088850340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70123088850340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70123088849640 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.1.rc
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70123088849640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70123088848800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70123088848800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70123088848260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70123088848260
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: turn
|
60
|
-
requirement: &
|
60
|
+
requirement: &70123088847780 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.8.3
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70123088847780
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
|
-
requirement: &
|
71
|
+
requirement: &70123088847200 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.6.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70123088847200
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: guard-minitest
|
82
|
-
requirement: &
|
82
|
+
requirement: &70123088846640 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 0.4.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70123088846640
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rb-fsevent
|
93
|
-
requirement: &
|
93
|
+
requirement: &70123088846160 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.4.1
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70123088846160
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: growl
|
104
|
-
requirement: &
|
104
|
+
requirement: &70123088845480 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 1.0.3
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70123088845480
|
113
113
|
description: Generate and validate license keys
|
114
114
|
email: evan@massivedanger.com
|
115
115
|
executables:
|
@@ -133,7 +133,7 @@ files:
|
|
133
133
|
- lib/cipher/version.rb
|
134
134
|
- test/helper.rb
|
135
135
|
- test/test_cipher.rb
|
136
|
-
homepage: http://github.com/
|
136
|
+
homepage: http://github.com/massivedanger/cipher
|
137
137
|
licenses:
|
138
138
|
- MIT
|
139
139
|
post_install_message:
|
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash:
|
151
|
+
hash: 2444294562060335112
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
none: false
|
154
154
|
requirements:
|