securer_randomer 0.1.2 → 0.1.3

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: b25fde6e0c3e17844dcdd32bcacfae1f2cfc57cf
4
- data.tar.gz: 6fb48d2b606b998396999db846ca19675f792c97
3
+ metadata.gz: 25d43122579ac392adc2e74c8fa6d28e1448bf0b
4
+ data.tar.gz: 3978081bda3f60f1e3badf4db94d136afb368d9a
5
5
  SHA512:
6
- metadata.gz: e3946831440182d688c7b94b6b62d901d85f50fda3f3a2dec5de3c7683354b1cecc901c6700b8f87626f79c20bd3d4d6f2b5e13096638d0b7434f2b56ff18a08
7
- data.tar.gz: ba921979c92ae96c114197db9c4190579f03661c0503b7f1b98ed7a38f9be15de866a088895f23824181ff649d6931195367c1cd8daf76ed27511b766959f3dd
6
+ metadata.gz: 509f3a5ea524c8f192cf6b9fea97b06d98727a4bc4929ed8ac1e6626c68a3db527cbbad3fc0e2d127cbf31067096e4323c93c26a4051204efa777ec102061865
7
+ data.tar.gz: ec2b8c5873cdd922f5fde5f663150e6773def66475e09e3303d02e6f92a5b560e9af6f7c55b36ddd501c67b248d9e8cf995ad2011d71dcd06afa937a94fe43a8
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/securer_randomer.svg)](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
- RUBY_VER_OBJ = Gem::Version.new(RUBY_VERSION.dup)
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 RUBY_GE_2_3
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecurerRandomer
4
- VERSION = '0.1.2' # rubocop:disable Style/MutableConstant
4
+ VERSION = '0.1.3' # rubocop:disable Style/MutableConstant
5
5
  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.2
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-09 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler