rubygems-update 3.5.18 → 3.5.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/Manifest.txt +10 -0
- data/bundler/CHANGELOG.md +41 -0
- data/bundler/lib/bundler/build_metadata.rb +2 -2
- data/bundler/lib/bundler/cli/add.rb +1 -1
- data/bundler/lib/bundler/cli/gem.rb +4 -1
- data/bundler/lib/bundler/cli/install.rb +5 -1
- data/bundler/lib/bundler/cli/lock.rb +5 -5
- data/bundler/lib/bundler/cli/outdated.rb +16 -18
- data/bundler/lib/bundler/definition.rb +4 -8
- data/bundler/lib/bundler/dsl.rb +27 -17
- data/bundler/lib/bundler/errors.rb +7 -5
- data/bundler/lib/bundler/fetcher.rb +2 -2
- data/bundler/lib/bundler/inline.rb +19 -4
- data/bundler/lib/bundler/installer/gem_installer.rb +4 -2
- data/bundler/lib/bundler/installer/parallel_installer.rb +3 -2
- data/bundler/lib/bundler/installer.rb +9 -11
- data/bundler/lib/bundler/man/bundle-add.1 +27 -16
- data/bundler/lib/bundler/man/bundle-add.1.ronn +37 -14
- data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
- data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
- data/bundler/lib/bundler/man/bundle-check.1 +1 -1
- data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
- data/bundler/lib/bundler/man/bundle-config.1 +1 -1
- data/bundler/lib/bundler/man/bundle-console.1 +1 -1
- data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
- data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
- data/bundler/lib/bundler/man/bundle-gem.1 +1 -1
- data/bundler/lib/bundler/man/bundle-help.1 +1 -1
- data/bundler/lib/bundler/man/bundle-info.1 +1 -1
- data/bundler/lib/bundler/man/bundle-init.1 +1 -1
- data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
- data/bundler/lib/bundler/man/bundle-install.1 +1 -1
- data/bundler/lib/bundler/man/bundle-list.1 +1 -1
- data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
- data/bundler/lib/bundler/man/bundle-open.1 +1 -1
- data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
- data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
- data/bundler/lib/bundler/man/bundle-plugin.1 +1 -1
- data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
- data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
- data/bundler/lib/bundler/man/bundle-show.1 +1 -1
- data/bundler/lib/bundler/man/bundle-update.1 +1 -1
- data/bundler/lib/bundler/man/bundle-version.1 +1 -1
- data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
- data/bundler/lib/bundler/man/bundle.1 +1 -1
- data/bundler/lib/bundler/man/gemfile.5 +3 -1
- data/bundler/lib/bundler/man/gemfile.5.ronn +6 -0
- data/bundler/lib/bundler/retry.rb +1 -1
- data/bundler/lib/bundler/ruby_version.rb +7 -1
- data/bundler/lib/bundler/rubygems_ext.rb +43 -16
- data/bundler/lib/bundler/rubygems_gem_installer.rb +4 -3
- data/bundler/lib/bundler/self_manager.rb +4 -4
- data/bundler/lib/bundler/source/git.rb +15 -6
- data/bundler/lib/bundler/source/rubygems.rb +5 -12
- data/bundler/lib/bundler/ui/shell.rb +24 -2
- data/bundler/lib/bundler/ui/silent.rb +12 -1
- data/bundler/lib/bundler/vendor/securerandom/.document +1 -0
- data/bundler/lib/bundler/vendor/securerandom/LICENSE.txt +22 -0
- data/bundler/lib/bundler/vendor/securerandom/lib/random/formatter.rb +373 -0
- data/bundler/lib/bundler/vendor/securerandom/lib/securerandom.rb +96 -0
- data/bundler/lib/bundler/vendored_securerandom.rb +14 -0
- data/bundler/lib/bundler/version.rb +1 -1
- data/bundler/lib/bundler.rb +1 -1
- data/lib/rubygems/commands/exec_command.rb +1 -6
- data/lib/rubygems/commands/fetch_command.rb +14 -0
- data/lib/rubygems/commands/install_command.rb +0 -4
- data/lib/rubygems/commands/setup_command.rb +2 -0
- data/lib/rubygems/exceptions.rb +2 -3
- data/lib/rubygems/installer.rb +1 -1
- data/lib/rubygems/remote_fetcher.rb +0 -1
- data/lib/rubygems/resolver/activation_request.rb +1 -1
- data/lib/rubygems/resolver/best_set.rb +2 -28
- data/lib/rubygems/source/git.rb +7 -5
- data/lib/rubygems/source/installed.rb +3 -1
- data/lib/rubygems/source/local.rb +8 -4
- data/lib/rubygems/source/specific_file.rb +5 -3
- data/lib/rubygems/source.rb +10 -8
- data/lib/rubygems/specification.rb +1 -1
- data/lib/rubygems/specification_policy.rb +1 -1
- data/lib/rubygems/vendor/molinillo/lib/molinillo/resolution.rb +1 -1
- data/lib/rubygems/vendor/net-http/lib/net/https.rb +1 -1
- data/lib/rubygems/vendor/optparse/lib/optparse.rb +1 -1
- data/lib/rubygems/vendor/resolv/lib/resolv.rb +71 -16
- data/lib/rubygems/vendor/securerandom/.document +1 -0
- data/lib/rubygems/vendor/securerandom/LICENSE.txt +22 -0
- data/lib/rubygems/vendor/securerandom/lib/random/formatter.rb +373 -0
- data/lib/rubygems/vendor/securerandom/lib/securerandom.rb +96 -0
- data/lib/rubygems/vendored_securerandom.rb +4 -0
- data/lib/rubygems.rb +18 -15
- data/rubygems-update.gemspec +1 -1
- metadata +13 -3
@@ -6,14 +6,17 @@ module Bundler
|
|
6
6
|
module UI
|
7
7
|
class Shell
|
8
8
|
LEVELS = %w[silent error warn confirm info debug].freeze
|
9
|
+
OUTPUT_STREAMS = [:stdout, :stderr].freeze
|
9
10
|
|
10
11
|
attr_writer :shell
|
12
|
+
attr_reader :output_stream
|
11
13
|
|
12
14
|
def initialize(options = {})
|
13
15
|
Thor::Base.shell = options["no-color"] ? Thor::Shell::Basic : nil
|
14
16
|
@shell = Thor::Base.shell.new
|
15
17
|
@level = ENV["DEBUG"] ? "debug" : "info"
|
16
18
|
@warning_history = []
|
19
|
+
@output_stream = :stdout
|
17
20
|
end
|
18
21
|
|
19
22
|
def add_color(string, *color)
|
@@ -84,7 +87,7 @@ module Bundler
|
|
84
87
|
@shell.yes?(msg)
|
85
88
|
end
|
86
89
|
|
87
|
-
def no?
|
90
|
+
def no?(msg)
|
88
91
|
@shell.no?(msg)
|
89
92
|
end
|
90
93
|
|
@@ -101,6 +104,11 @@ module Bundler
|
|
101
104
|
index <= LEVELS.index(@level)
|
102
105
|
end
|
103
106
|
|
107
|
+
def output_stream=(symbol)
|
108
|
+
raise ArgumentError unless OUTPUT_STREAMS.include?(symbol)
|
109
|
+
@output_stream = symbol
|
110
|
+
end
|
111
|
+
|
104
112
|
def trace(e, newline = nil, force = false)
|
105
113
|
return unless debug? || force
|
106
114
|
msg = "#{e.class}: #{e.message}\n#{e.backtrace.join("\n ")}"
|
@@ -111,6 +119,10 @@ module Bundler
|
|
111
119
|
with_level("silent", &blk)
|
112
120
|
end
|
113
121
|
|
122
|
+
def progress(&blk)
|
123
|
+
with_output_stream(:stderr, &blk)
|
124
|
+
end
|
125
|
+
|
114
126
|
def unprinted_warnings
|
115
127
|
[]
|
116
128
|
end
|
@@ -119,6 +131,8 @@ module Bundler
|
|
119
131
|
|
120
132
|
# valimism
|
121
133
|
def tell_me(msg, color = nil, newline = nil)
|
134
|
+
return tell_err(msg, color, newline) if output_stream == :stderr
|
135
|
+
|
122
136
|
msg = word_wrap(msg) if newline.is_a?(Hash) && newline[:wrap]
|
123
137
|
if newline.nil?
|
124
138
|
@shell.say(msg, color)
|
@@ -130,7 +144,7 @@ module Bundler
|
|
130
144
|
def tell_err(message, color = nil, newline = nil)
|
131
145
|
return if @shell.send(:stderr).closed?
|
132
146
|
|
133
|
-
newline
|
147
|
+
newline = !message.to_s.match?(/( |\t)\Z/) if newline.nil?
|
134
148
|
message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap]
|
135
149
|
|
136
150
|
color = nil if color && !$stderr.tty?
|
@@ -160,6 +174,14 @@ module Bundler
|
|
160
174
|
ensure
|
161
175
|
@level = original
|
162
176
|
end
|
177
|
+
|
178
|
+
def with_output_stream(symbol)
|
179
|
+
original = output_stream
|
180
|
+
self.output_stream = symbol
|
181
|
+
yield
|
182
|
+
ensure
|
183
|
+
@output_stream = original
|
184
|
+
end
|
163
185
|
end
|
164
186
|
end
|
165
187
|
end
|
@@ -53,6 +53,13 @@ module Bundler
|
|
53
53
|
false
|
54
54
|
end
|
55
55
|
|
56
|
+
def output_stream=(_symbol)
|
57
|
+
end
|
58
|
+
|
59
|
+
def output_stream
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
56
63
|
def ask(message)
|
57
64
|
end
|
58
65
|
|
@@ -60,7 +67,7 @@ module Bundler
|
|
60
67
|
raise "Cannot ask yes? with a silent shell"
|
61
68
|
end
|
62
69
|
|
63
|
-
def no?
|
70
|
+
def no?(msg)
|
64
71
|
raise "Cannot ask no? with a silent shell"
|
65
72
|
end
|
66
73
|
|
@@ -77,6 +84,10 @@ module Bundler
|
|
77
84
|
yield
|
78
85
|
end
|
79
86
|
|
87
|
+
def progress
|
88
|
+
yield
|
89
|
+
end
|
90
|
+
|
80
91
|
def unprinted_warnings
|
81
92
|
@warnings
|
82
93
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Vendored files do not need to be documented
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
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.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
@@ -0,0 +1,373 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# == \Random number formatter.
|
5
|
+
#
|
6
|
+
# Formats generated random numbers in many manners. When <tt>'random/formatter'</tt>
|
7
|
+
# is required, several methods are added to empty core module <tt>Bundler::Random::Formatter</tt>,
|
8
|
+
# making them available as Random's instance and module methods.
|
9
|
+
#
|
10
|
+
# Standard library Bundler::SecureRandom is also extended with the module, and the methods
|
11
|
+
# described below are available as a module methods in it.
|
12
|
+
#
|
13
|
+
# === Examples
|
14
|
+
#
|
15
|
+
# Generate random hexadecimal strings:
|
16
|
+
#
|
17
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
18
|
+
#
|
19
|
+
# prng = Random.new
|
20
|
+
# prng.hex(10) #=> "52750b30ffbc7de3b362"
|
21
|
+
# prng.hex(10) #=> "92b15d6c8dc4beb5f559"
|
22
|
+
# prng.hex(13) #=> "39b290146bea6ce975c37cfc23"
|
23
|
+
# # or just
|
24
|
+
# Random.hex #=> "1aed0c631e41be7f77365415541052ee"
|
25
|
+
#
|
26
|
+
# Generate random base64 strings:
|
27
|
+
#
|
28
|
+
# prng.base64(10) #=> "EcmTPZwWRAozdA=="
|
29
|
+
# prng.base64(10) #=> "KO1nIU+p9DKxGg=="
|
30
|
+
# prng.base64(12) #=> "7kJSM/MzBJI+75j8"
|
31
|
+
# Random.base64(4) #=> "bsQ3fQ=="
|
32
|
+
#
|
33
|
+
# Generate random binary strings:
|
34
|
+
#
|
35
|
+
# prng.random_bytes(10) #=> "\016\t{\370g\310pbr\301"
|
36
|
+
# prng.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
|
37
|
+
# Random.random_bytes(6) #=> "\xA1\xE6Lr\xC43"
|
38
|
+
#
|
39
|
+
# Generate alphanumeric strings:
|
40
|
+
#
|
41
|
+
# prng.alphanumeric(10) #=> "S8baxMJnPl"
|
42
|
+
# prng.alphanumeric(10) #=> "aOxAg8BAJe"
|
43
|
+
# Random.alphanumeric #=> "TmP9OsJHJLtaZYhP"
|
44
|
+
#
|
45
|
+
# Generate UUIDs:
|
46
|
+
#
|
47
|
+
# prng.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
|
48
|
+
# prng.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
|
49
|
+
# Random.uuid #=> "f14e0271-de96-45cc-8911-8910292a42cd"
|
50
|
+
#
|
51
|
+
# All methods are available in the standard library Bundler::SecureRandom, too:
|
52
|
+
#
|
53
|
+
# Bundler::SecureRandom.hex #=> "05b45376a30c67238eb93b16499e50cf"
|
54
|
+
|
55
|
+
module Bundler::Random::Formatter
|
56
|
+
|
57
|
+
# Generate a random binary string.
|
58
|
+
#
|
59
|
+
# The argument _n_ specifies the length of the result string.
|
60
|
+
#
|
61
|
+
# If _n_ is not specified or is nil, 16 is assumed.
|
62
|
+
# It may be larger in future.
|
63
|
+
#
|
64
|
+
# The result may contain any byte: "\x00" - "\xff".
|
65
|
+
#
|
66
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
67
|
+
#
|
68
|
+
# Random.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6"
|
69
|
+
# # or
|
70
|
+
# prng = Random.new
|
71
|
+
# prng.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
|
72
|
+
def random_bytes(n=nil)
|
73
|
+
n = n ? n.to_int : 16
|
74
|
+
gen_random(n)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Generate a random hexadecimal string.
|
78
|
+
#
|
79
|
+
# The argument _n_ specifies the length, in bytes, of the random number to be generated.
|
80
|
+
# The length of the resulting hexadecimal string is twice of _n_.
|
81
|
+
#
|
82
|
+
# If _n_ is not specified or is nil, 16 is assumed.
|
83
|
+
# It may be larger in the future.
|
84
|
+
#
|
85
|
+
# The result may contain 0-9 and a-f.
|
86
|
+
#
|
87
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
88
|
+
#
|
89
|
+
# Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
|
90
|
+
# # or
|
91
|
+
# prng = Random.new
|
92
|
+
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
|
93
|
+
def hex(n=nil)
|
94
|
+
random_bytes(n).unpack1("H*")
|
95
|
+
end
|
96
|
+
|
97
|
+
# Generate a random base64 string.
|
98
|
+
#
|
99
|
+
# The argument _n_ specifies the length, in bytes, of the random number
|
100
|
+
# to be generated. The length of the result string is about 4/3 of _n_.
|
101
|
+
#
|
102
|
+
# If _n_ is not specified or is nil, 16 is assumed.
|
103
|
+
# It may be larger in the future.
|
104
|
+
#
|
105
|
+
# The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
|
106
|
+
#
|
107
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
108
|
+
#
|
109
|
+
# Random.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
|
110
|
+
# # or
|
111
|
+
# prng = Random.new
|
112
|
+
# prng.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
|
113
|
+
#
|
114
|
+
# See RFC 3548 for the definition of base64.
|
115
|
+
def base64(n=nil)
|
116
|
+
[random_bytes(n)].pack("m0")
|
117
|
+
end
|
118
|
+
|
119
|
+
# Generate a random URL-safe base64 string.
|
120
|
+
#
|
121
|
+
# The argument _n_ specifies the length, in bytes, of the random number
|
122
|
+
# to be generated. The length of the result string is about 4/3 of _n_.
|
123
|
+
#
|
124
|
+
# If _n_ is not specified or is nil, 16 is assumed.
|
125
|
+
# It may be larger in the future.
|
126
|
+
#
|
127
|
+
# The boolean argument _padding_ specifies the padding.
|
128
|
+
# If it is false or nil, padding is not generated.
|
129
|
+
# Otherwise padding is generated.
|
130
|
+
# By default, padding is not generated because "=" may be used as a URL delimiter.
|
131
|
+
#
|
132
|
+
# The result may contain A-Z, a-z, 0-9, "-" and "_".
|
133
|
+
# "=" is also used if _padding_ is true.
|
134
|
+
#
|
135
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
136
|
+
#
|
137
|
+
# Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
|
138
|
+
# # or
|
139
|
+
# prng = Random.new
|
140
|
+
# prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
|
141
|
+
#
|
142
|
+
# prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
|
143
|
+
# prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
|
144
|
+
#
|
145
|
+
# See RFC 3548 for the definition of URL-safe base64.
|
146
|
+
def urlsafe_base64(n=nil, padding=false)
|
147
|
+
s = [random_bytes(n)].pack("m0")
|
148
|
+
s.tr!("+/", "-_")
|
149
|
+
s.delete!("=") unless padding
|
150
|
+
s
|
151
|
+
end
|
152
|
+
|
153
|
+
# Generate a random v4 UUID (Universally Unique IDentifier).
|
154
|
+
#
|
155
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
156
|
+
#
|
157
|
+
# Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
|
158
|
+
# Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
|
159
|
+
# # or
|
160
|
+
# prng = Random.new
|
161
|
+
# prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
|
162
|
+
#
|
163
|
+
# The version 4 UUID is purely random (except the version).
|
164
|
+
# It doesn't contain meaningful information such as MAC addresses, timestamps, etc.
|
165
|
+
#
|
166
|
+
# The result contains 122 random bits (15.25 random bytes).
|
167
|
+
#
|
168
|
+
# See RFC4122[https://datatracker.ietf.org/doc/html/rfc4122] for details of UUID.
|
169
|
+
#
|
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
|
175
|
+
end
|
176
|
+
|
177
|
+
alias uuid_v4 uuid
|
178
|
+
|
179
|
+
# Generate a random v7 UUID (Universally Unique IDentifier).
|
180
|
+
#
|
181
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
182
|
+
#
|
183
|
+
# Random.uuid_v7 # => "0188d4c3-1311-7f96-85c7-242a7aa58f1e"
|
184
|
+
# Random.uuid_v7 # => "0188d4c3-16fe-744f-86af-38fa04c62bb5"
|
185
|
+
# Random.uuid_v7 # => "0188d4c3-1af8-764f-b049-c204ce0afa23"
|
186
|
+
# Random.uuid_v7 # => "0188d4c3-1e74-7085-b14f-ef6415dc6f31"
|
187
|
+
# # |<--sorted-->| |<----- random ---->|
|
188
|
+
#
|
189
|
+
# # or
|
190
|
+
# prng = Random.new
|
191
|
+
# prng.uuid_v7 # => "0188ca51-5e72-7950-a11d-def7ff977c98"
|
192
|
+
#
|
193
|
+
# The version 7 UUID starts with the least significant 48 bits of a 64 bit
|
194
|
+
# Unix timestamp (milliseconds since the epoch) and fills the remaining bits
|
195
|
+
# with random data, excluding the version and variant bits.
|
196
|
+
#
|
197
|
+
# This allows version 7 UUIDs to be sorted by creation time. Time ordered
|
198
|
+
# UUIDs can be used for better database index locality of newly inserted
|
199
|
+
# records, which may have a significant performance benefit compared to random
|
200
|
+
# data inserts.
|
201
|
+
#
|
202
|
+
# The result contains 74 random bits (9.25 random bytes).
|
203
|
+
#
|
204
|
+
# Note that this method cannot be made reproducable because its output
|
205
|
+
# includes not only random bits but also timestamp.
|
206
|
+
#
|
207
|
+
# See draft-ietf-uuidrev-rfc4122bis[https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/]
|
208
|
+
# for details of UUIDv7.
|
209
|
+
#
|
210
|
+
# ==== Monotonicity
|
211
|
+
#
|
212
|
+
# UUIDv7 has millisecond precision by default, so multiple UUIDs created
|
213
|
+
# within the same millisecond are not issued in monotonically increasing
|
214
|
+
# order. To create UUIDs that are time-ordered with sub-millisecond
|
215
|
+
# precision, up to 12 bits of additional timestamp may added with
|
216
|
+
# +extra_timestamp_bits+. The extra timestamp precision comes at the expense
|
217
|
+
# of random bits. Setting <tt>extra_timestamp_bits: 12</tt> provides ~244ns
|
218
|
+
# of precision, but only 62 random bits (7.75 random bytes).
|
219
|
+
#
|
220
|
+
# prng = Random.new
|
221
|
+
# Array.new(4) { prng.uuid_v7(extra_timestamp_bits: 12) }
|
222
|
+
# # =>
|
223
|
+
# ["0188d4c7-13da-74f9-8b53-22a786ffdd5a",
|
224
|
+
# "0188d4c7-13da-753b-83a5-7fb9b2afaeea",
|
225
|
+
# "0188d4c7-13da-754a-88ea-ac0baeedd8db",
|
226
|
+
# "0188d4c7-13da-7557-83e1-7cad9cda0d8d"]
|
227
|
+
# # |<--- sorted --->| |<-- random --->|
|
228
|
+
#
|
229
|
+
# Array.new(4) { prng.uuid_v7(extra_timestamp_bits: 8) }
|
230
|
+
# # =>
|
231
|
+
# ["0188d4c7-3333-7a95-850a-de6edb858f7e",
|
232
|
+
# "0188d4c7-3333-7ae8-842e-bc3a8b7d0cf9", # <- out of order
|
233
|
+
# "0188d4c7-3333-7ae2-995a-9f135dc44ead", # <- out of order
|
234
|
+
# "0188d4c7-3333-7af9-87c3-8f612edac82e"]
|
235
|
+
# # |<--- sorted -->||<---- random --->|
|
236
|
+
#
|
237
|
+
# Any rollbacks of the system clock will break monotonicity. UUIDv7 is based
|
238
|
+
# on UTC, which excludes leap seconds and can rollback the clock. To avoid
|
239
|
+
# this, the system clock can synchronize with an NTP server configured to use
|
240
|
+
# a "leap smear" approach. NTP or PTP will also be needed to synchronize
|
241
|
+
# across distributed nodes.
|
242
|
+
#
|
243
|
+
# Counters and other mechanisms for stronger guarantees of monotonicity are
|
244
|
+
# not implemented. Applications with stricter requirements should follow
|
245
|
+
# {Section 6.2}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-07.html#monotonicity_counters]
|
246
|
+
# of the specification.
|
247
|
+
#
|
248
|
+
def uuid_v7(extra_timestamp_bits: 0)
|
249
|
+
case (extra_timestamp_bits = Integer(extra_timestamp_bits))
|
250
|
+
when 0 # min timestamp precision
|
251
|
+
ms = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
|
252
|
+
rand = random_bytes(10)
|
253
|
+
rand.setbyte(0, rand.getbyte(0) & 0x0f | 0x70) # version
|
254
|
+
rand.setbyte(2, rand.getbyte(2) & 0x3f | 0x80) # variant
|
255
|
+
"%08x-%04x-%s" % [
|
256
|
+
(ms & 0x0000_ffff_ffff_0000) >> 16,
|
257
|
+
(ms & 0x0000_0000_0000_ffff),
|
258
|
+
rand.unpack("H4H4H12").join("-")
|
259
|
+
]
|
260
|
+
|
261
|
+
when 12 # max timestamp precision
|
262
|
+
ms, ns = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
|
263
|
+
.divmod(1_000_000)
|
264
|
+
extra_bits = ns * 4096 / 1_000_000
|
265
|
+
rand = random_bytes(8)
|
266
|
+
rand.setbyte(0, rand.getbyte(0) & 0x3f | 0x80) # variant
|
267
|
+
"%08x-%04x-7%03x-%s" % [
|
268
|
+
(ms & 0x0000_ffff_ffff_0000) >> 16,
|
269
|
+
(ms & 0x0000_0000_0000_ffff),
|
270
|
+
extra_bits,
|
271
|
+
rand.unpack("H4H12").join("-")
|
272
|
+
]
|
273
|
+
|
274
|
+
when (0..12) # the generic version is slower than the special cases above
|
275
|
+
rand_a, rand_b1, rand_b2, rand_b3 = random_bytes(10).unpack("nnnN")
|
276
|
+
rand_mask_bits = 12 - extra_timestamp_bits
|
277
|
+
ms, ns = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
|
278
|
+
.divmod(1_000_000)
|
279
|
+
"%08x-%04x-%04x-%04x-%04x%08x" % [
|
280
|
+
(ms & 0x0000_ffff_ffff_0000) >> 16,
|
281
|
+
(ms & 0x0000_0000_0000_ffff),
|
282
|
+
0x7000 |
|
283
|
+
((ns * (1 << extra_timestamp_bits) / 1_000_000) << rand_mask_bits) |
|
284
|
+
rand_a & ((1 << rand_mask_bits) - 1),
|
285
|
+
0x8000 | (rand_b1 & 0x3fff),
|
286
|
+
rand_b2,
|
287
|
+
rand_b3
|
288
|
+
]
|
289
|
+
|
290
|
+
else
|
291
|
+
raise ArgumentError, "extra_timestamp_bits must be in 0..12"
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
# Internal interface to Random; Generate random data _n_ bytes.
|
296
|
+
private def gen_random(n)
|
297
|
+
self.bytes(n)
|
298
|
+
end
|
299
|
+
|
300
|
+
# Generate a string that randomly draws from a
|
301
|
+
# source array of characters.
|
302
|
+
#
|
303
|
+
# The argument _source_ specifies the array of characters from which
|
304
|
+
# to generate the string.
|
305
|
+
# The argument _n_ specifies the length, in characters, of the string to be
|
306
|
+
# generated.
|
307
|
+
#
|
308
|
+
# The result may contain whatever characters are in the source array.
|
309
|
+
#
|
310
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
311
|
+
#
|
312
|
+
# prng.choose([*'l'..'r'], 16) #=> "lmrqpoonmmlqlron"
|
313
|
+
# prng.choose([*'0'..'9'], 5) #=> "27309"
|
314
|
+
private def choose(source, n)
|
315
|
+
size = source.size
|
316
|
+
m = 1
|
317
|
+
limit = size
|
318
|
+
while limit * size <= 0x100000000
|
319
|
+
limit *= size
|
320
|
+
m += 1
|
321
|
+
end
|
322
|
+
result = ''.dup
|
323
|
+
while m <= n
|
324
|
+
rs = random_number(limit)
|
325
|
+
is = rs.digits(size)
|
326
|
+
(m-is.length).times { is << 0 }
|
327
|
+
result << source.values_at(*is).join('')
|
328
|
+
n -= m
|
329
|
+
end
|
330
|
+
if 0 < n
|
331
|
+
rs = random_number(limit)
|
332
|
+
is = rs.digits(size)
|
333
|
+
if is.length < n
|
334
|
+
(n-is.length).times { is << 0 }
|
335
|
+
else
|
336
|
+
is.pop while n < is.length
|
337
|
+
end
|
338
|
+
result.concat source.values_at(*is).join('')
|
339
|
+
end
|
340
|
+
result
|
341
|
+
end
|
342
|
+
|
343
|
+
# The default character list for #alphanumeric.
|
344
|
+
ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9']
|
345
|
+
|
346
|
+
# Generate a random alphanumeric string.
|
347
|
+
#
|
348
|
+
# The argument _n_ specifies the length, in characters, of the alphanumeric
|
349
|
+
# string to be generated.
|
350
|
+
# The argument _chars_ specifies the character list which the result is
|
351
|
+
# consist of.
|
352
|
+
#
|
353
|
+
# If _n_ is not specified or is nil, 16 is assumed.
|
354
|
+
# It may be larger in the future.
|
355
|
+
#
|
356
|
+
# The result may contain A-Z, a-z and 0-9, unless _chars_ is specified.
|
357
|
+
#
|
358
|
+
# require 'bundler/vendor/securerandom/lib/random/formatter'
|
359
|
+
#
|
360
|
+
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
|
361
|
+
# # or
|
362
|
+
# prng = Random.new
|
363
|
+
# prng.alphanumeric(10) #=> "i6K93NdqiH"
|
364
|
+
#
|
365
|
+
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
|
366
|
+
# # or
|
367
|
+
# prng = Random.new
|
368
|
+
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
|
369
|
+
def alphanumeric(n = nil, chars: ALPHANUMERIC)
|
370
|
+
n = 16 if n.nil?
|
371
|
+
choose(chars, n)
|
372
|
+
end
|
373
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'random/formatter'
|
5
|
+
|
6
|
+
# == Secure random number generator interface.
|
7
|
+
#
|
8
|
+
# This library is an interface to secure random number generators which are
|
9
|
+
# suitable for generating session keys in HTTP cookies, etc.
|
10
|
+
#
|
11
|
+
# You can use this library in your application by requiring it:
|
12
|
+
#
|
13
|
+
# require 'bundler/vendor/securerandom/lib/securerandom'
|
14
|
+
#
|
15
|
+
# It supports the following secure random number generators:
|
16
|
+
#
|
17
|
+
# * openssl
|
18
|
+
# * /dev/urandom
|
19
|
+
# * Win32
|
20
|
+
#
|
21
|
+
# Bundler::SecureRandom is extended by the Bundler::Random::Formatter module which
|
22
|
+
# defines the following methods:
|
23
|
+
#
|
24
|
+
# * alphanumeric
|
25
|
+
# * base64
|
26
|
+
# * choose
|
27
|
+
# * gen_random
|
28
|
+
# * hex
|
29
|
+
# * rand
|
30
|
+
# * random_bytes
|
31
|
+
# * random_number
|
32
|
+
# * urlsafe_base64
|
33
|
+
# * uuid
|
34
|
+
#
|
35
|
+
# These methods are usable as class methods of Bundler::SecureRandom such as
|
36
|
+
# +Bundler::SecureRandom.hex+.
|
37
|
+
#
|
38
|
+
# If a secure random number generator is not available,
|
39
|
+
# +NotImplementedError+ is raised.
|
40
|
+
|
41
|
+
module Bundler::SecureRandom
|
42
|
+
|
43
|
+
# The version
|
44
|
+
VERSION = "0.3.1"
|
45
|
+
|
46
|
+
class << self
|
47
|
+
# Returns a random binary string containing +size+ bytes.
|
48
|
+
#
|
49
|
+
# See Random.bytes
|
50
|
+
def bytes(n)
|
51
|
+
return gen_random(n)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
# :stopdoc:
|
57
|
+
|
58
|
+
# Implementation using OpenSSL
|
59
|
+
def gen_random_openssl(n)
|
60
|
+
return OpenSSL::Random.random_bytes(n)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Implementation using system random device
|
64
|
+
def gen_random_urandom(n)
|
65
|
+
ret = Random.urandom(n)
|
66
|
+
unless ret
|
67
|
+
raise NotImplementedError, "No random device"
|
68
|
+
end
|
69
|
+
unless ret.length == n
|
70
|
+
raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes"
|
71
|
+
end
|
72
|
+
ret
|
73
|
+
end
|
74
|
+
|
75
|
+
begin
|
76
|
+
# Check if Random.urandom is available
|
77
|
+
Random.urandom(1)
|
78
|
+
alias gen_random gen_random_urandom
|
79
|
+
rescue RuntimeError
|
80
|
+
begin
|
81
|
+
require 'openssl'
|
82
|
+
rescue NoMethodError
|
83
|
+
raise NotImplementedError, "No random device"
|
84
|
+
else
|
85
|
+
alias gen_random gen_random_openssl
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# :startdoc:
|
90
|
+
|
91
|
+
# Generate random data bytes for Bundler::Random::Formatter
|
92
|
+
public :gen_random
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Bundler::SecureRandom.extend(Bundler::Random::Formatter)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Use RubyGems vendored copy when available. Otherwise fallback to Bundler
|
4
|
+
# vendored copy. The vendored copy in Bundler can be removed once support for
|
5
|
+
# RubyGems 3.5.18 is dropped.
|
6
|
+
|
7
|
+
begin
|
8
|
+
require "rubygems/vendored_securerandom"
|
9
|
+
rescue LoadError
|
10
|
+
module Bundler::Random; end
|
11
|
+
require_relative "vendor/securerandom/lib/securerandom"
|
12
|
+
Gem::SecureRandom = Bundler::SecureRandom
|
13
|
+
Gem::Random = Bundler::Random
|
14
|
+
end
|
data/bundler/lib/bundler.rb
CHANGED
@@ -652,7 +652,7 @@ module Bundler
|
|
652
652
|
rescue ScriptError, StandardError => e
|
653
653
|
msg = "There was an error while loading `#{path.basename}`: #{e.message}"
|
654
654
|
|
655
|
-
raise GemspecError, Dsl::DSLError.new(msg, path, e.backtrace, contents)
|
655
|
+
raise GemspecError, Dsl::DSLError.new(msg, path.to_s, e.backtrace, contents)
|
656
656
|
end
|
657
657
|
|
658
658
|
def configure_gem_path
|
@@ -57,8 +57,6 @@ to the same gem path as user-installed gems.
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def execute
|
60
|
-
gem_paths = { "GEM_HOME" => Gem.paths.home, "GEM_PATH" => Gem.paths.path.join(File::PATH_SEPARATOR), "GEM_SPEC_CACHE" => Gem.paths.spec_cache_dir }.compact
|
61
|
-
|
62
60
|
check_executable
|
63
61
|
|
64
62
|
print_command
|
@@ -74,9 +72,6 @@ to the same gem path as user-installed gems.
|
|
74
72
|
end
|
75
73
|
|
76
74
|
load!
|
77
|
-
ensure
|
78
|
-
ENV.update(gem_paths) if gem_paths
|
79
|
-
Gem.clear_paths
|
80
75
|
end
|
81
76
|
|
82
77
|
private
|
@@ -143,7 +138,7 @@ to the same gem path as user-installed gems.
|
|
143
138
|
end
|
144
139
|
|
145
140
|
def set_gem_exec_install_paths
|
146
|
-
home =
|
141
|
+
home = Gem.dir
|
147
142
|
|
148
143
|
ENV["GEM_PATH"] = ([home] + Gem.path).join(File::PATH_SEPARATOR)
|
149
144
|
ENV["GEM_HOME"] = home
|