securerandom 0.3.0 → 0.3.2

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
  SHA256:
3
- metadata.gz: 1e5fca1a0e74f7d256340e2b2e12196ed97adc8ebc512697473d56c110fe682c
4
- data.tar.gz: 19d45327f812eede26a7a1432381e8c43d114ca0268ea1697b727db5c94c5ca9
3
+ metadata.gz: 6f14853630e9280f98e432e1da48fd1eb894a7376c4e3678dc97639e28929c3d
4
+ data.tar.gz: 79846163a70d7b0198271a61ce63a7320c9a141dd59d0912a91e9a5259353999
5
5
  SHA512:
6
- metadata.gz: e36e2adb4f23bf29d52a519e68e89dd5c947803399fd493bdab26c452e38142f11d7af03ef436f70c6f7a3c8881cee75b179167b5376556dfc91e4ab3f8ccc46
7
- data.tar.gz: 0e86593665d73afc22c91f6964df05f6134dc3b75b443932dde93ee38d296c692478b456a95110e042c4ff7dc54ccefb6cad84847dcd8a3e97d47736a6f25a6c
6
+ metadata.gz: 7d448c439592c67f07e543c855fa4c06e6da72ce84d31ade33ea97d76d5ee90952b575c938a34bf8e11453353920582d0d5311cf9212b6ba7397fa3d038bc2e5
7
+ data.tar.gz: c3080d88c1a11a88ca3a28ddc6e173ab5afbf6027d60c353263ed9f78b8982a55dcc15c4a88cc3f2a44ba6e8a5933d7283af91b2f38965f67ebd68e636d78922
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
8
  2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
11
 
12
12
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
13
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -165,13 +165,13 @@ module Random::Formatter
165
165
  #
166
166
  # The result contains 122 random bits (15.25 random bytes).
167
167
  #
168
- # See RFC4122[https://datatracker.ietf.org/doc/html/rfc4122] for details of UUID.
168
+ # See RFC9562[https://www.rfc-editor.org/rfc/rfc9562] for details of UUIDv4.
169
169
  #
170
170
  def uuid
171
- ary = random_bytes(16).unpack("NnnnnN")
172
- ary[2] = (ary[2] & 0x0fff) | 0x4000
173
- ary[3] = (ary[3] & 0x3fff) | 0x8000
174
- "%08x-%04x-%04x-%04x-%04x%08x" % ary
171
+ ary = random_bytes(16)
172
+ ary.setbyte(6, (ary.getbyte(6) & 0x0f) | 0x40)
173
+ ary.setbyte(8, (ary.getbyte(8) & 0x3f) | 0x80)
174
+ ary.unpack("H8H4H4H4H12").join(?-)
175
175
  end
176
176
 
177
177
  alias uuid_v4 uuid
@@ -201,12 +201,10 @@ module Random::Formatter
201
201
  #
202
202
  # The result contains 74 random bits (9.25 random bytes).
203
203
  #
204
- # Note that this method cannot be made reproducable with Kernel#srand, which
205
- # can only affect the random bits. The sorted bits will still be based on
206
- # Process.clock_gettime.
204
+ # Note that this method cannot be made reproducible because its output
205
+ # includes not only random bits but also timestamp.
207
206
  #
208
- # See draft-ietf-uuidrev-rfc4122bis[https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/]
209
- # for details of UUIDv7.
207
+ # See RFC9562[https://www.rfc-editor.org/rfc/rfc9562] for details of UUIDv7.
210
208
  #
211
209
  # ==== Monotonicity
212
210
  #
@@ -243,7 +241,7 @@ module Random::Formatter
243
241
  #
244
242
  # Counters and other mechanisms for stronger guarantees of monotonicity are
245
243
  # not implemented. Applications with stricter requirements should follow
246
- # {Section 6.2}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-07.html#monotonicity_counters]
244
+ # {Section 6.2}[https://www.rfc-editor.org/rfc/rfc9562.html#name-monotonicity-and-counters]
247
245
  # of the specification.
248
246
  #
249
247
  def uuid_v7(extra_timestamp_bits: 0)
@@ -293,6 +291,7 @@ module Random::Formatter
293
291
  end
294
292
  end
295
293
 
294
+ # Internal interface to Random; Generate random data _n_ bytes.
296
295
  private def gen_random(n)
297
296
  self.bytes(n)
298
297
  end
@@ -340,7 +339,9 @@ module Random::Formatter
340
339
  result
341
340
  end
342
341
 
342
+ # The default character list for #alphanumeric.
343
343
  ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9']
344
+
344
345
  # Generate a random alphanumeric string.
345
346
  #
346
347
  # The argument _n_ specifies the length, in characters, of the alphanumeric
data/lib/securerandom.rb CHANGED
@@ -40,19 +40,27 @@ require 'random/formatter'
40
40
 
41
41
  module SecureRandom
42
42
 
43
- VERSION = "0.3.0"
43
+ # The version
44
+ VERSION = "0.3.2"
44
45
 
45
46
  class << self
47
+ # Returns a random binary string containing +size+ bytes.
48
+ #
49
+ # See Random.bytes
46
50
  def bytes(n)
47
51
  return gen_random(n)
48
52
  end
49
53
 
50
54
  private
51
55
 
56
+ # :stopdoc:
57
+
58
+ # Implementation using OpenSSL
52
59
  def gen_random_openssl(n)
53
60
  return OpenSSL::Random.random_bytes(n)
54
61
  end
55
62
 
63
+ # Implementation using system random device
56
64
  def gen_random_urandom(n)
57
65
  ret = Random.urandom(n)
58
66
  unless ret
@@ -78,6 +86,9 @@ module SecureRandom
78
86
  end
79
87
  end
80
88
 
89
+ # :startdoc:
90
+
91
+ # Generate random data bytes for Random::Formatter
81
92
  public :gen_random
82
93
  end
83
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securerandom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Interface for secure random number generator.
14
14
  email:
@@ -17,19 +17,11 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".github/dependabot.yml"
21
- - ".github/workflows/test.yml"
22
- - ".gitignore"
23
- - Gemfile
24
- - LICENSE.txt
20
+ - BSDL
21
+ - COPYING
25
22
  - README.md
26
- - Rakefile
27
- - bin/console
28
- - bin/setup
29
23
  - lib/random/formatter.rb
30
24
  - lib/securerandom.rb
31
- - rakelib/epoch.rake
32
- - securerandom.gemspec
33
25
  homepage: https://github.com/ruby/securerandom
34
26
  licenses:
35
27
  - Ruby
@@ -37,7 +29,7 @@ licenses:
37
29
  metadata:
38
30
  homepage_uri: https://github.com/ruby/securerandom
39
31
  source_code_uri: https://github.com/ruby/securerandom
40
- post_install_message:
32
+ post_install_message:
41
33
  rdoc_options: []
42
34
  require_paths:
43
35
  - lib
@@ -52,8 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
44
  - !ruby/object:Gem::Version
53
45
  version: '0'
54
46
  requirements: []
55
- rubygems_version: 3.5.0.dev
56
- signing_key:
47
+ rubygems_version: 3.5.11
48
+ signing_key:
57
49
  specification_version: 4
58
50
  summary: Interface for secure random number generator.
59
51
  test_files: []
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: 'github-actions'
4
- directory: '/'
5
- schedule:
6
- interval: 'weekly'
@@ -1,29 +0,0 @@
1
- name: test
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- ruby-versions:
7
- uses: ruby/actions/.github/workflows/ruby_versions.yml@master
8
- with:
9
- engine: cruby
10
- min_version: 2.6
11
-
12
- test:
13
- needs: ruby-versions
14
- name: build (${{ matrix.ruby }} / ${{ matrix.os }})
15
- strategy:
16
- matrix:
17
- ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
18
- os: [ ubuntu-latest, macos-latest, windows-latest ]
19
- runs-on: ${{ matrix.os }}
20
- steps:
21
- - uses: actions/checkout@v4
22
- - name: Set up Ruby
23
- uses: ruby/setup-ruby@v1
24
- with:
25
- ruby-version: ${{ matrix.ruby }}
26
- - name: Install dependencies
27
- run: bundle install
28
- - name: Run test
29
- run: rake test
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "rake"
4
- gem "test-unit"
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/test_*.rb"]
8
- end
9
-
10
- task :default => :test
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "securerandom"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/rakelib/epoch.rake DELETED
@@ -1,5 +0,0 @@
1
- task "build" => "date_epoch"
2
-
3
- task "date_epoch" do
4
- ENV["SOURCE_DATE_EPOCH"] = IO.popen(%W[git -C #{__dir__} log -1 --format=%ct], &:read).chomp
5
- end
data/securerandom.gemspec DELETED
@@ -1,29 +0,0 @@
1
- name = File.basename(__FILE__, ".gemspec")
2
- version = ["lib", Array.new(name.count("-")+1).join("/")].find do |dir|
3
- break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
4
- /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
5
- end rescue nil
6
- end
7
-
8
- Gem::Specification.new do |spec|
9
- spec.name = name
10
- spec.version = version
11
- spec.authors = ["Tanaka Akira"]
12
- spec.email = ["akr@fsij.org"]
13
-
14
- spec.summary = %q{Interface for secure random number generator.}
15
- spec.description = %q{Interface for secure random number generator.}
16
- spec.homepage = "https://github.com/ruby/securerandom"
17
- spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
18
- spec.licenses = ["Ruby", "BSD-2-Clause"]
19
-
20
- spec.metadata["homepage_uri"] = spec.homepage
21
- spec.metadata["source_code_uri"] = spec.homepage
22
-
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
- end