sysrandom 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/CHANGES.md +6 -0
- data/README.md +8 -5
- data/ext/sysrandom/sysrandom_ext.c +7 -3
- data/lib/sysrandom.rb +7 -5
- data/lib/sysrandom/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 456a8666aa44a8e588164327d3113f1c4830eea2
|
4
|
+
data.tar.gz: f18bb61b2a390a76a233adbb75f79bd919a63bbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75dc28b3174189a732bc942cfc11bcd5067b6b424975316e6462b3bb4311ce8fcd194808c10a5ba6b84dfaa92be2e41c57c25f0cf830fc57dc8e3a89b1590deb
|
7
|
+
data.tar.gz: dd2aae0d61a1294b53f321797df922cd6badb331487a9edc4383c062a5cfb4bb64e3215d67039472ac5c0bf457344b0fa81cc3f308721de043fdf93b4dd3452b
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
# Sysrandom
|
2
|
-
|
3
|
-
[
|
4
|
-
[
|
5
|
-
[
|
1
|
+
# Sysrandom [![Gem Version][gem-image]][gem-link] [![Build Status][build-image]][build-link] [![ISC licensed][license-image]][license-link]
|
2
|
+
|
3
|
+
[gem-image]: https://badge.fury.io/rb/sysrandom.svg
|
4
|
+
[gem-link]: https://rubygems.org/gems/sysrandom
|
5
|
+
[build-image]: https://secure.travis-ci.org/cryptosphere/sysrandom.svg?branch=master
|
6
|
+
[build-link]: https://travis-ci.org/cryptosphere/sysrandom
|
7
|
+
[license-image]: https://img.shields.io/badge/license-ISC-blue.svg
|
8
|
+
[license-link]: https://github.com/cryptosphere/sysrandom/blob/master/LICENSE.txt
|
6
9
|
|
7
10
|
Secure random number generation for Ruby using system RNG facilities e.g. `/dev/urandom`, `getrandom(2)`
|
8
11
|
|
@@ -58,10 +58,14 @@ Sysrandom_random_bytes(int argc, VALUE * argv, VALUE self)
|
|
58
58
|
int n;
|
59
59
|
|
60
60
|
if (rb_scan_args(argc, argv, "01", &n_obj) == 1) {
|
61
|
-
|
61
|
+
if(n_obj == Qnil) {
|
62
|
+
n = DEFAULT_N_BYTES;
|
63
|
+
} else {
|
64
|
+
n = NUM2INT(n_obj);
|
62
65
|
|
63
|
-
|
64
|
-
|
66
|
+
if(n < 0) {
|
67
|
+
rb_raise(rb_eArgError, "negative string size");
|
68
|
+
}
|
65
69
|
}
|
66
70
|
} else {
|
67
71
|
n = DEFAULT_N_BYTES;
|
data/lib/sysrandom.rb
CHANGED
@@ -26,7 +26,8 @@ module Sysrandom
|
|
26
26
|
@_java_secure_random.nextLong & 0xFFFFFFFF
|
27
27
|
end
|
28
28
|
|
29
|
-
def random_bytes(n =
|
29
|
+
def random_bytes(n = nil)
|
30
|
+
n ||= DEFAULT_LENGTH
|
30
31
|
raise ArgumentError, "negative string size" if n < 0
|
31
32
|
return "" if n == 0
|
32
33
|
|
@@ -49,15 +50,16 @@ module Sysrandom
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
def base64(n =
|
53
|
+
def base64(n = nil)
|
53
54
|
Base64.encode64(random_bytes(n)).chomp
|
54
55
|
end
|
55
56
|
|
56
|
-
def urlsafe_base64(n =
|
57
|
-
Base64.urlsafe_encode64(random_bytes(n)).chomp
|
57
|
+
def urlsafe_base64(n = nil, padding = false)
|
58
|
+
result = Base64.urlsafe_encode64(random_bytes(n)).chomp
|
59
|
+
padding ? result : result.tr("=", "")
|
58
60
|
end
|
59
61
|
|
60
|
-
def hex(n =
|
62
|
+
def hex(n = nil)
|
61
63
|
random_bytes(n).unpack("h*").first
|
62
64
|
end
|
63
65
|
|
data/lib/sysrandom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sysrandom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Sysrandom generates secure random numbers using /dev/urandom, getrandom(),
|
14
14
|
etc
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.5.
|
60
|
+
rubygems_version: 2.5.2
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: Secure random number generation using system RNG facilities
|