dionysus 1.0.1 → 1.0.2
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.
- data/README.md +1 -1
- data/VERSION +1 -1
- data/dionysus.gemspec +7 -4
- data/lib/dionysus.rb +6 -1
- data/lib/dionysus/configuration.rb +6 -1
- data/lib/dionysus/security/password_salt.rb +8 -1
- data/lib/dionysus/security/string.rb +16 -4
- data/lib/dionysus/version_string.rb +96 -0
- data/spec/version_string_spec.rb +83 -0
- metadata +7 -4
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Installation
|
|
21
21
|
Usage
|
22
22
|
-----
|
23
23
|
|
24
|
-
First, add "dionysus" to your Gemfile or whatever other dependency system you're using. Then, you'll need to require each file as you need them. Dionysus is setup *à la carte* since parts are bound to conflict with something you're using at some point.
|
24
|
+
First, add "dionysus" to your Gemfile or whatever other dependency system you're using. Then, you'll need to require each file/module as you need them. Dionysus is setup *à la carte* since parts are bound to conflict with something you're using at some point.
|
25
25
|
|
26
26
|
Resources
|
27
27
|
---------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/dionysus.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dionysus}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Travis D. Warlick, Jr."]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-03}
|
13
13
|
s.email = %q{warlickt@operissystems.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -35,13 +35,15 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/dionysus/security/password_salt.rb",
|
36
36
|
"lib/dionysus/security/string.rb",
|
37
37
|
"lib/dionysus/string.rb",
|
38
|
+
"lib/dionysus/version_string.rb",
|
38
39
|
"spec/configuration_spec.rb",
|
39
40
|
"spec/digest_spec.rb",
|
40
41
|
"spec/dionysus_spec.rb",
|
41
42
|
"spec/password_salt_spec.rb",
|
42
43
|
"spec/spec_helper.rb",
|
43
44
|
"spec/string_security_spec.rb",
|
44
|
-
"spec/string_spec.rb"
|
45
|
+
"spec/string_spec.rb",
|
46
|
+
"spec/version_string_spec.rb"
|
45
47
|
]
|
46
48
|
s.homepage = %q{http://github.com/tekwiz/dionysus}
|
47
49
|
s.require_paths = ["lib"]
|
@@ -54,7 +56,8 @@ Gem::Specification.new do |s|
|
|
54
56
|
"spec/password_salt_spec.rb",
|
55
57
|
"spec/spec_helper.rb",
|
56
58
|
"spec/string_security_spec.rb",
|
57
|
-
"spec/string_spec.rb"
|
59
|
+
"spec/string_spec.rb",
|
60
|
+
"spec/version_string_spec.rb"
|
58
61
|
]
|
59
62
|
|
60
63
|
if s.respond_to? :specification_version then
|
data/lib/dionysus.rb
CHANGED
@@ -18,7 +18,12 @@ Bundler.setup
|
|
18
18
|
%w(hash class module).each { |v| require 'active_support/core_ext/'+v }
|
19
19
|
|
20
20
|
##
|
21
|
-
# The top-level for Dionysus
|
21
|
+
# The top-level for Dionysus.
|
22
|
+
#
|
23
|
+
# Dionysus is setup *à la carte* since parts are bound to conflict with
|
24
|
+
# something you're using at some point. This means that if you need something,
|
25
|
+
# you *must* require it. See the documentation for instructions on what you
|
26
|
+
# should require (this is always within the first few lines).
|
22
27
|
module Dionysus
|
23
28
|
# The current version
|
24
29
|
VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'dionysus'
|
2
|
+
require 'dionysus/version_string'
|
2
3
|
|
3
4
|
##
|
4
5
|
# = Configuration
|
@@ -117,7 +118,11 @@ class Configuration
|
|
117
118
|
def valid_key?( key )
|
118
119
|
return false if key.blank?
|
119
120
|
key = _normalize_key(key).to_s
|
120
|
-
|
121
|
+
if RUBY_VERSION.satisfies?('>= 1.9.2')
|
122
|
+
key =~ /^#{VALID_KEY}$/ and !self.methods.include?(key.to_sym)
|
123
|
+
else
|
124
|
+
key =~ /^#{VALID_KEY}$/ and !self.methods.include?(key)
|
125
|
+
end
|
121
126
|
end
|
122
127
|
|
123
128
|
##
|
@@ -2,7 +2,14 @@ require 'dionysus'
|
|
2
2
|
require 'active_support/secure_random'
|
3
3
|
|
4
4
|
##
|
5
|
-
# Encapsulates a password salt.
|
5
|
+
# Encapsulates a password salt. This is usually not required specifically,
|
6
|
+
# instead it's required as a part of the security module:
|
7
|
+
#
|
8
|
+
# require 'dionysus/security'
|
9
|
+
#
|
10
|
+
# However, you may require it specifically:
|
11
|
+
#
|
12
|
+
# require 'dionysus/security/password_salt'
|
6
13
|
#
|
7
14
|
# Examples
|
8
15
|
#
|
@@ -2,6 +2,7 @@ require 'dionysus'
|
|
2
2
|
require 'dionysus/digest'
|
3
3
|
require 'dionysus/string'
|
4
4
|
require 'dionysus/security/password_salt'
|
5
|
+
require 'dionysus/version_string'
|
5
6
|
|
6
7
|
##
|
7
8
|
# Adds String hashing and salting convenience methods.
|
@@ -26,12 +27,23 @@ class String
|
|
26
27
|
# Sanitize the String from memory. This is non-reversible. Runs 7 passes
|
27
28
|
# by default.
|
28
29
|
#
|
30
|
+
# NOTE: In Ruby 1.9, this uses the String#setbyte(index, int) method. In Ruby < 1.9, this
|
31
|
+
# uses String#[]=(int)
|
32
|
+
#
|
29
33
|
def sanitize( passes = 7 )
|
30
|
-
|
31
|
-
|
34
|
+
if RUBY_VERSION.satisfies?('< 1.9')
|
35
|
+
passes.times do
|
36
|
+
(0...self.length).each { |i| self[i] = rand(256) }
|
37
|
+
end
|
38
|
+
(0...self.length).each { |i| self[i] = 0 }
|
39
|
+
self.delete!("\000")
|
40
|
+
elsif RUBY_VERSION.satisfies?('>= 1.9')
|
41
|
+
passes.times do
|
42
|
+
(0...self.length).each { |i| self.setbyte(i, rand(256)) }
|
43
|
+
end
|
44
|
+
(0...self.length).each { |i| self.setbyte(i, 0) }
|
45
|
+
self.clear
|
32
46
|
end
|
33
|
-
(0...self.length).each { |i| self[i] = 0.chr }
|
34
|
-
self.delete!("\000")
|
35
47
|
end
|
36
48
|
|
37
49
|
##
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'dionysus'
|
2
|
+
require 'active_support/core_ext/kernel/reporting'
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
5
|
+
module Dionysus
|
6
|
+
##
|
7
|
+
# = VersonString
|
8
|
+
#
|
9
|
+
# require 'dionysus/version_string'
|
10
|
+
#
|
11
|
+
# VersionString is a proxy to Gem::Version that modifies the comparable
|
12
|
+
# interface on String to compare based on the Gem::Version comparator.
|
13
|
+
# It also adds a +satisfies?+ method to check for a Gem::Requirement.
|
14
|
+
#
|
15
|
+
# In addition, requiring VersionString changes the +RUBY_VERSION+ constant
|
16
|
+
# into a VersionString. Because VersionString "is a" String, there should be
|
17
|
+
# no ill-effects with this change since only the Comparable interface is
|
18
|
+
# overriden and this does not change the original operation of the == method.
|
19
|
+
#
|
20
|
+
# The comparator works by converting strings into Gem::Version objects, so
|
21
|
+
# this still works as you would expect:
|
22
|
+
#
|
23
|
+
# RUBY_VERSION < '1.9'
|
24
|
+
class VersionString < String
|
25
|
+
include Comparable
|
26
|
+
|
27
|
+
##
|
28
|
+
# Initializes a VersionString and freezes itself.
|
29
|
+
def initialize(*args)
|
30
|
+
super(*args)
|
31
|
+
to_rubygem_version
|
32
|
+
freeze
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Compares this VersionString to another String, VersionString, or
|
37
|
+
# Gem::Version.
|
38
|
+
#
|
39
|
+
# Examples:
|
40
|
+
#
|
41
|
+
# Dionysus::VersionString.new('1.0') > '1.0' => false
|
42
|
+
# Dionysus::VersionString.new('1.0') == Gem::Version('1.0') => true
|
43
|
+
# Dionysus::VersionString.new('1.0') <=> Dionysus::VersionString.new('1.0') => 0
|
44
|
+
#
|
45
|
+
# See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html
|
46
|
+
def <=>( obj )
|
47
|
+
obj = obj.dup
|
48
|
+
if obj.is_a?(String) or obj.is_a?(Gem::Version)
|
49
|
+
obj = Gem::Version.create(obj)
|
50
|
+
else
|
51
|
+
raise ArgumentError, "Can only compare to a Dionysus::VersionString/String or Gem::Version"
|
52
|
+
end
|
53
|
+
|
54
|
+
self.to_rubygem_version <=> obj
|
55
|
+
end
|
56
|
+
alias_method :"eql?", :"=="
|
57
|
+
|
58
|
+
##
|
59
|
+
# Determines if the given requirement String or Gem::Requirement is
|
60
|
+
# satisfied by this version.
|
61
|
+
#
|
62
|
+
# Examples:
|
63
|
+
#
|
64
|
+
# Dionysus::VersionString.new('1.6.7').satisfies? '~> 1.6.0' => true
|
65
|
+
# Dionysus::VersionString.new('1.6.7').satisfies? Gem::Requirement('< 1.6') => false
|
66
|
+
#
|
67
|
+
# See http://rubygems.rubyforge.org/rubygems-update/Gem/Requirement.html
|
68
|
+
def satisfies?( requirement )
|
69
|
+
requirement = requirement.dup
|
70
|
+
if requirement.is_a?(String) or requirement.is_a?(Gem::Requirement)
|
71
|
+
requirement = Gem::Requirement.create(requirement)
|
72
|
+
else
|
73
|
+
raise ArgumentError, "Can only compare to a String or Gem::Requirement"
|
74
|
+
end
|
75
|
+
|
76
|
+
requirement.satisfied_by?(to_rubygem_version)
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Converts this VersionString into a Gem::Version
|
81
|
+
def to_rubygem_version
|
82
|
+
@rubygem_version ||= Gem::Version.create(self)
|
83
|
+
end
|
84
|
+
alias_method :to_gem_version, :to_rubygem_version
|
85
|
+
|
86
|
+
##
|
87
|
+
# Indicates whether this VersionString is a prerelease.
|
88
|
+
#
|
89
|
+
# See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html#method-i-prerelease%3F
|
90
|
+
def prerelease?() to_rubygem_version.prerelease?; end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
silence_warnings do
|
95
|
+
RUBY_VERSION = Dionysus::VersionString.new(RUBY_VERSION)
|
96
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'dionysus/version_string'
|
4
|
+
describe Dionysus::VersionString do
|
5
|
+
before(:each) do
|
6
|
+
@version_string = Dionysus::VersionString.new('1.5.7')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should be frozen' do
|
10
|
+
@version_string.should be_frozen
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have to_rubygem_version' do
|
14
|
+
@version_string.to_rubygem_version.should be_a(Gem::Version)
|
15
|
+
gem_version = @version_string.to_gem_version
|
16
|
+
@version_string.to_rubygem_version.should eq(gem_version)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should have prerelease? that delegates to Gem::Version' do
|
20
|
+
@version_string.should_not be_prerelease
|
21
|
+
version = Dionysus::VersionString.new('1.5.alpha')
|
22
|
+
version.should be_prerelease
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have eql?' do
|
26
|
+
(@version_string.eql?('1.5.7')).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'comparable' do
|
30
|
+
before(:all) do
|
31
|
+
@values = {'1.5.7' => 0, '1.5' => 1, '1.6' => -1}
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should work with VersionStrings' do
|
35
|
+
@values.each do |ver, c|
|
36
|
+
(@version_string <=> Dionysus::VersionString.new(ver)).should == c
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should work with Strings' do
|
41
|
+
@values.each do |ver, c|
|
42
|
+
(@version_string <=> ver).should == c
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should work with Gem::Versions' do
|
47
|
+
@values.each do |ver, c|
|
48
|
+
(@version_string <=> Gem::Version.new(ver.dup)) == c
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not work with anything else' do
|
53
|
+
lambda {
|
54
|
+
@version_string <=> Object.new
|
55
|
+
}.should raise_error(ArgumentError, "Can only compare to a Dionysus::VersionString/String or Gem::Version")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'satisfies?' do
|
60
|
+
before(:all) do
|
61
|
+
@values = {'~> 1.5.0' => true, '~> 2' => false}
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should work with Strings' do
|
65
|
+
@values.each do |req, v|
|
66
|
+
@version_string.satisfies?(req).should == v
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should work with Gem::Requirements' do
|
71
|
+
@values.each do |req, v|
|
72
|
+
@version_string.satisfies?(Gem::Requirement.new(req)).should == v
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should not work with anything else' do
|
77
|
+
lambda {
|
78
|
+
@version_string.satisfies?(Object.new)
|
79
|
+
}.should raise_error(ArgumentError, "Can only compare to a String or Gem::Requirement")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis D. Warlick, Jr.
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-03 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -284,6 +284,7 @@ files:
|
|
284
284
|
- lib/dionysus/security/password_salt.rb
|
285
285
|
- lib/dionysus/security/string.rb
|
286
286
|
- lib/dionysus/string.rb
|
287
|
+
- lib/dionysus/version_string.rb
|
287
288
|
- spec/configuration_spec.rb
|
288
289
|
- spec/digest_spec.rb
|
289
290
|
- spec/dionysus_spec.rb
|
@@ -291,6 +292,7 @@ files:
|
|
291
292
|
- spec/spec_helper.rb
|
292
293
|
- spec/string_security_spec.rb
|
293
294
|
- spec/string_spec.rb
|
295
|
+
- spec/version_string_spec.rb
|
294
296
|
has_rdoc: true
|
295
297
|
homepage: http://github.com/tekwiz/dionysus
|
296
298
|
licenses: []
|
@@ -305,7 +307,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
305
307
|
requirements:
|
306
308
|
- - ">="
|
307
309
|
- !ruby/object:Gem::Version
|
308
|
-
hash:
|
310
|
+
hash: -737655002021028068
|
309
311
|
segments:
|
310
312
|
- 0
|
311
313
|
version: "0"
|
@@ -332,3 +334,4 @@ test_files:
|
|
332
334
|
- spec/spec_helper.rb
|
333
335
|
- spec/string_security_spec.rb
|
334
336
|
- spec/string_spec.rb
|
337
|
+
- spec/version_string_spec.rb
|