securer_randomer 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/securer_randomer/monkeypatch/secure_random.rb +5 -13
- data/lib/securer_randomer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d43122579ac392adc2e74c8fa6d28e1448bf0b
|
4
|
+
data.tar.gz: 3978081bda3f60f1e3badf4db94d136afb368d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509f3a5ea524c8f192cf6b9fea97b06d98727a4bc4929ed8ac1e6626c68a3db527cbbad3fc0e2d127cbf31067096e4323c93c26a4051204efa777ec102061865
|
7
|
+
data.tar.gz: ec2b8c5873cdd922f5fde5f663150e6773def66475e09e3303d02e6f92a5b560e9af6f7c55b36ddd501c67b248d9e8cf995ad2011d71dcd06afa937a94fe43a8
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://badge.fury.io/rb/securer_randomer)
|
5
5
|
|
6
6
|
Ruby's SecureRandom prefers OpenSSL over other mechanisms (such as
|
7
|
-
`/dev/urandom` and `getrandom()`). This has recently garnered [some][1]
|
7
|
+
`/dev/urandom` and `getrandom(2)`). This has recently garnered [some][1]
|
8
8
|
[criticism][2].
|
9
9
|
|
10
10
|
[RbNaCl][3] provides Ruby bindings to a portable crypto library
|
@@ -3,11 +3,7 @@
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
5
|
module SecureRandom
|
6
|
-
|
7
|
-
RUBY_GE_2_2 = RUBY_VER_OBJ >= Gem::Version.new(String.new('2.2.0'))
|
8
|
-
RUBY_GE_2_3 = RUBY_VER_OBJ >= Gem::Version.new(String.new('2.3.0'))
|
9
|
-
|
10
|
-
if RUBY_GE_2_2
|
6
|
+
if respond_to?(:gen_random)
|
11
7
|
def self.gen_random(n)
|
12
8
|
RbNaCl::Random.random_bytes(n)
|
13
9
|
end
|
@@ -17,7 +13,7 @@ module SecureRandom
|
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
20
|
-
if
|
16
|
+
if (random_number(nil) rescue nil)
|
21
17
|
def self.random_number(n = 0)
|
22
18
|
arg =
|
23
19
|
case n
|
@@ -36,15 +32,11 @@ module SecureRandom
|
|
36
32
|
raise ArgumentError, "invalid argument - #{n}"
|
37
33
|
end
|
38
34
|
else
|
35
|
+
FLOAT_ERROR = begin random_number(1.0); rescue => e; e end
|
36
|
+
|
39
37
|
def self.random_number(n = 0)
|
40
38
|
raise ArgumentError, "comparison of Fixnum with #{n} failed" unless n.is_a?(Numeric)
|
41
|
-
if n.is_a?(Float) and n > 0
|
42
|
-
if RUBY_GE_2_2
|
43
|
-
raise TypeError, 'Cannot convert into OpenSSL::BN'
|
44
|
-
else
|
45
|
-
raise ArgumentError, 'wrong number of arguments'
|
46
|
-
end
|
47
|
-
end
|
39
|
+
raise FLOAT_ERROR if n.is_a?(Float) and n > 0
|
48
40
|
|
49
41
|
SecurerRandomer.rand(n > 0 ? n : 0, true)
|
50
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: securer_randomer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Pastore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|