securer_randomer 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78ef5479ad3ab003521008c6187af14d0fd1bc95
4
- data.tar.gz: b8de5c893bcdae29488f1001445c73031f667f1d
3
+ metadata.gz: 7cba7c11c88f376cd4e607ce3257ead37f85627a
4
+ data.tar.gz: 9b8f50ff4c3ded6e183525eec67e92f3384ed856
5
5
  SHA512:
6
- metadata.gz: f0ad82e2504fbaec7836f307a5406adf40c1e68af9eb1254440c9bc0b16e310659102e8ceee0a72b444f2dea580fa00590c973d58dcd52b6d3901ae695238d95
7
- data.tar.gz: 06ef5ada69966a6e9811267098e8ecc3702f63eefad7e51160583d8390220f0149af2599e9b6f0537086f869564240e18fa0edd9d35b87ae243f300d7dbb879c
6
+ metadata.gz: eb8dc02d517df6ccc33c3ef75faec746f6ed659d8185115bb147cef400d575212637ebc44df23a68fa430f5472a2020086b023cdcb4f186530935d140caf4602
7
+ data.tar.gz: f0c6807fad93b80a32318642b16a8ebbb4b43ef090743dbd737283bce4610ddf99a4d5f298ce03a9be682d7e590d1369144fb0f06527200172c293262bcc4e23
data/.travis.yml CHANGED
@@ -7,6 +7,10 @@ rvm:
7
7
  - 2.1.8
8
8
  - 2.2.4
9
9
  - 2.3.0
10
+ - jruby-1.7.23
11
+ - jruby-9.0.5.0
12
+ jdk:
13
+ - oraclejdk8
10
14
  before_install:
11
15
  - gem install bundler -v 1.11.2
12
16
  - sudo add-apt-repository -y ppa:chris-lea/libsodium
data/README.md CHANGED
@@ -92,7 +92,7 @@ Or install it yourself as:
92
92
  ## Compatibility
93
93
 
94
94
  SecurerRandomer has been tested under MRI/YARV versions 1.9.3, 2.0, 2.1, 2.2,
95
- and 2.3.
95
+ and 2.3, and JRuby 1.7 and 9.0 (both under Oracle Java 8).
96
96
 
97
97
  ## DISCLAIMER
98
98
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'securerandom'
4
-
5
3
  module SecureRandom
6
4
  if respond_to?(:gen_random)
7
5
  def self.gen_random(n)
@@ -19,6 +17,8 @@ module SecureRandom
19
17
  case n
20
18
  when nil
21
19
  0
20
+ when Numeric
21
+ n > 0 ? n : 0
22
22
  when Range
23
23
  if n.end < n.begin
24
24
  0
@@ -27,8 +27,6 @@ module SecureRandom
27
27
  else
28
28
  n
29
29
  end
30
- when Numeric
31
- n > 0 ? n : 0
32
30
  end
33
31
 
34
32
  raise TypeError unless arg
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SecurerRandomer
4
+ def self.kernel_rand(max = 0)
5
+ rand(max, true)
6
+ end
7
+
8
+ def self.rand(n = 0, emulate_kernel = false)
9
+ if n.is_a?(Range)
10
+ unless n.begin.is_a?(Numeric) and n.end.is_a?(Numeric)
11
+ if emulate_kernel and defined?(JRUBY_VERSION)
12
+ raise NoMethodError, "undefined method `-' for \"#{n.end}\""
13
+ else
14
+ raise TypeError, 'no implicit conversion of Range into Fixnum'
15
+ end
16
+ end
17
+
18
+ if n.end < n.begin
19
+ if emulate_kernel
20
+ raise ArgumentError, "invalid argument - #{n}" if defined?(JRUBY_VERSION)
21
+
22
+ nil
23
+ else
24
+ m = Range.new(n.end, n.begin, false)
25
+
26
+ while true # TODO: better way to do this than looping?
27
+ q = _rand_range(m)
28
+
29
+ break q unless n.exclude_end? and q == n.end
30
+ end
31
+ end
32
+ elsif n.begin == n.end and n.exclude_end?
33
+ raise ArgumentError, "invalid argument - #{n}" if emulate_kernel and defined?(JRUBY_VERSION)
34
+
35
+ nil
36
+ else
37
+ _rand_range(n)
38
+ end
39
+ else
40
+ raise TypeError, "no implicit conversion of #{n.class} into Fixnum" \
41
+ unless n.nil? or n.is_a?(Numeric)
42
+
43
+ if n.nil? or n.zero?
44
+ _randex
45
+ elsif emulate_kernel
46
+ _rand_range(Range.new(0, n.to_i.abs, true))
47
+ else
48
+ _rand_range(Range.new(0, n.abs, true)) * (n < 0 ? -1 : 1)
49
+ end
50
+ end
51
+ end
52
+
53
+ def self._randex
54
+ i64 = RbNaCl::Random.random_bytes(8).unpack('Q').first
55
+ Math.ldexp(i64 >> (64 - Float::MANT_DIG), -Float::MANT_DIG)
56
+ end
57
+
58
+ def self._randin
59
+ _randex >= 0.5 ? 1 - _randex : _randex
60
+ end
61
+
62
+ def self._rand_range(n)
63
+ n.begin + if n.end.is_a?(Float) or n.begin.is_a?(Float)
64
+ (n.exclude_end? ? _randex : _randin) * (n.end - n.begin)
65
+ else
66
+ (_randex * (n.end - n.begin + (n.exclude_end? ? 0 : 1))).to_i
67
+ end
68
+ end
69
+
70
+ private_class_method(:_randex, :_randin, :_rand_range) if respond_to?(:private_class_method)
71
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecurerRandomer
4
- VERSION = '0.1.4' # rubocop:disable Style/MutableConstant
4
+ VERSION = '0.1.5' # rubocop:disable Style/MutableConstant
5
5
  end
@@ -1,69 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'securerandom'
4
+
3
5
  require 'rbnacl/sodium'
4
6
  require 'rbnacl/util'
5
7
  require 'rbnacl/random'
6
8
 
7
9
  require 'securer_randomer/version'
10
+ require 'securer_randomer/rand'
8
11
  require 'securer_randomer/monkeypatch/secure_random'
9
-
10
- module SecurerRandomer
11
- def self.kernel_rand(max = 0)
12
- rand(max, true)
13
- end
14
-
15
- def self.rand(n = 0, emulate_kernel = false)
16
- if n.is_a?(Range)
17
- raise TypeError, 'no implicit conversion of Range into Fixnum' \
18
- unless n.begin.is_a?(Numeric) and n.end.is_a?(Numeric)
19
-
20
- if n.end < n.begin
21
- if emulate_kernel
22
- nil
23
- else
24
- m = Range.new(n.end, n.begin, false)
25
-
26
- while true # TODO: better way to do this than looping?
27
- q = _rand_range(m)
28
-
29
- break q unless n.exclude_end? and q == n.end
30
- end
31
- end
32
- elsif n.begin == n.end and n.exclude_end?
33
- nil
34
- else
35
- _rand_range(n)
36
- end
37
- else
38
- raise TypeError, "no implicit conversion of #{n.class} into Fixnum" \
39
- unless n.nil? or n.is_a?(Numeric)
40
-
41
- if n.nil? or n.zero?
42
- _randex
43
- elsif emulate_kernel
44
- _rand_range(Range.new(0, n.to_i.abs, true))
45
- else
46
- _rand_range(Range.new(0, n.abs, true)) * (n < 0 ? -1 : 1)
47
- end
48
- end
49
- end
50
-
51
- def self._randex
52
- i64 = RbNaCl::Random.random_bytes(8).unpack('Q').first
53
- Math.ldexp(i64 >> (64 - Float::MANT_DIG), -Float::MANT_DIG)
54
- end
55
-
56
- def self._randin
57
- _randex >= 0.5 ? 1 - _randex : _randex
58
- end
59
-
60
- def self._rand_range(n)
61
- n.begin + if n.end.is_a?(Float) or n.begin.is_a?(Float)
62
- (n.exclude_end? ? _randex : _randin) * (n.end - n.begin)
63
- else
64
- (_randex * (n.end - n.begin + (n.exclude_end? ? 0 : 1))).to_i
65
- end
66
- end
67
-
68
- private_class_method(:_randex, :_randin, :_rand_range) if respond_to?(:private_class_method)
69
- end
metadata CHANGED
@@ -1,100 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securer_randomer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Pastore
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.11'
20
- type: :development
19
+ name: bundler
21
20
  prerelease: false
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
32
  version: 11.1.1
34
- type: :development
33
+ name: rake
35
34
  prerelease: false
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 11.1.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
46
  version: '3.0'
48
- type: :development
47
+ name: rspec
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec-given
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
60
  version: 3.8.0
62
- type: :development
61
+ name: rspec-given
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.8.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - "~>"
74
73
  - !ruby/object:Gem::Version
75
74
  version: 0.39.0
76
- type: :development
75
+ name: rubocop
77
76
  prerelease: false
77
+ type: :development
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.39.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: rbnacl
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
88
  version: 3.3.0
90
- type: :runtime
89
+ name: rbnacl
91
90
  prerelease: false
91
+ type: :runtime
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.3.0
97
- description:
97
+ description:
98
98
  email:
99
99
  - mike@oobak.org
100
100
  executables: []
@@ -113,13 +113,14 @@ files:
113
113
  - bin/setup
114
114
  - lib/securer_randomer.rb
115
115
  - lib/securer_randomer/monkeypatch/secure_random.rb
116
+ - lib/securer_randomer/rand.rb
116
117
  - lib/securer_randomer/version.rb
117
118
  - securer_randomer.gemspec
118
119
  homepage: https://github.com/mwpastore/securer_randomer
119
120
  licenses:
120
121
  - MIT
121
122
  metadata: {}
122
- post_install_message:
123
+ post_install_message:
123
124
  rdoc_options: []
124
125
  require_paths:
125
126
  - lib
@@ -134,9 +135,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.5.1
139
- signing_key:
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.8
140
+ signing_key:
140
141
  specification_version: 4
141
142
  summary: Monkeypatch SecureRandom with RbNaCl
142
143
  test_files: []