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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b09e764d20a1a07bf2e7f87a93f295592c575ca
4
- data.tar.gz: 23189ac23947a740ec6c8ccaabd248cbb482428b
3
+ metadata.gz: 456a8666aa44a8e588164327d3113f1c4830eea2
4
+ data.tar.gz: f18bb61b2a390a76a233adbb75f79bd919a63bbf
5
5
  SHA512:
6
- metadata.gz: 3ca2fcfbd1ff6bbe5e414c085f190f7a66bd406f51ea0eb7b66dd84a206df1d8dbf01400b8e4c89be9398beca9377cc111baeea65e73137583441a4657c6c6c3
7
- data.tar.gz: 9881ce341e7e03d6b58f0063f34e9a631b8006b2152249b9c69c7e91508d3e9d587534cad79f3734c496aaa93f7d4d9aaad62fecf973865100468153cbcc4618
6
+ metadata.gz: 75dc28b3174189a732bc942cfc11bcd5067b6b424975316e6462b3bb4311ce8fcd194808c10a5ba6b84dfaa92be2e41c57c25f0cf830fc57dc8e3a89b1590deb
7
+ data.tar.gz: dd2aae0d61a1294b53f321797df922cd6badb331487a9edc4383c062a5cfb4bb64e3215d67039472ac5c0bf457344b0fa81cc3f308721de043fdf93b4dd3452b
@@ -1,9 +1,15 @@
1
1
  sudo: false
2
2
  language: ruby
3
+
4
+ branches:
5
+ only:
6
+ - master
7
+
3
8
  rvm:
4
9
  - 2.0
5
10
  - 2.1
6
11
  - 2.2
7
12
  - 2.3.1
8
13
  - jruby-9.1.1.0
14
+
9
15
  before_install: gem install bundler -v 1.12.3
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.0.4 (2016-12-04)
2
+
3
+ * [#15](https://github.com/cryptosphere/sysrandom/pull/16)
4
+ Argument handling fixups.
5
+ ([@tarcieri])
6
+
1
7
  ## 1.0.3 (2016-09-27)
2
8
 
3
9
  * [#14](https://github.com/cryptosphere/sysrandom/pull/14)
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
- # Sysrandom
2
-
3
- [![Gem Version](https://badge.fury.io/rb/sysrandom.svg)](https://rubygems.org/gems/sysrandom)
4
- [![Build Status](https://secure.travis-ci.org/cryptosphere/sysrandom.svg?branch=master)](https://travis-ci.org/cryptosphere/sysrandom)
5
- [![ISC licensed](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/cryptosphere/sysrandom/blob/master/LICENSE.txt)
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
- n = NUM2INT(n_obj);
61
+ if(n_obj == Qnil) {
62
+ n = DEFAULT_N_BYTES;
63
+ } else {
64
+ n = NUM2INT(n_obj);
62
65
 
63
- if(n < 0) {
64
- rb_raise(rb_eArgError, "negative string size");
66
+ if(n < 0) {
67
+ rb_raise(rb_eArgError, "negative string size");
68
+ }
65
69
  }
66
70
  } else {
67
71
  n = DEFAULT_N_BYTES;
@@ -26,7 +26,8 @@ module Sysrandom
26
26
  @_java_secure_random.nextLong & 0xFFFFFFFF
27
27
  end
28
28
 
29
- def random_bytes(n = DEFAULT_LENGTH)
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 = DEFAULT_LENGTH)
53
+ def base64(n = nil)
53
54
  Base64.encode64(random_bytes(n)).chomp
54
55
  end
55
56
 
56
- def urlsafe_base64(n = DEFAULT_LENGTH)
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 = DEFAULT_LENGTH)
62
+ def hex(n = nil)
61
63
  random_bytes(n).unpack("h*").first
62
64
  end
63
65
 
@@ -1,3 +1,3 @@
1
1
  module Sysrandom
2
- VERSION = "1.0.3".freeze
2
+ VERSION = "1.0.4".freeze
3
3
  end
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.3
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-09-28 00:00:00.000000000 Z
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.1
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