uri-ni 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/uri/ni/version.rb +1 -1
- data/lib/uri/ni.rb +28 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e205294ee6b137c97fca41dfe3017b8fcfe41e28ba949002ba00167d216c3dd8
|
|
4
|
+
data.tar.gz: d81cbabc67dc1ed564d790232011119e1b3eec87044531680e6db77f2bc728a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 85745faf2e879e90a233f60f937b9f55adcfcca2cb06e4871ebfab119ba98bc88517b8907baafb50412cbdd6af7342dbdadc1f0652382ad96a614cd64084b56c
|
|
7
|
+
data.tar.gz: fe3bd0a1fef2939489dc31dc463e7038f632a771f0d9feb17b72617c37bc19cfae78eb19d304b7f06f85694114ea6cafb34d0065e664147c9516bd0078cfe97e
|
data/lib/uri/ni/version.rb
CHANGED
data/lib/uri/ni.rb
CHANGED
|
@@ -161,8 +161,18 @@ class URI::NI < URI::Generic
|
|
|
161
161
|
public
|
|
162
162
|
|
|
163
163
|
# Compute an RFC6920 URI from a data source.
|
|
164
|
+
#
|
|
164
165
|
# @param data [#to_s, IO, Digest, nil]
|
|
165
|
-
# @param algorithm [Symbol] See algorithms
|
|
166
|
+
# @param algorithm [Symbol] See available algorithms. Default: +:"sha-256"+
|
|
167
|
+
# @param blocksize [Integer] The number or bytes per call to the Digest
|
|
168
|
+
# @param authority [String, nil] Optional authority (user, host, port)
|
|
169
|
+
# @param query [String, nil] Optional query string
|
|
170
|
+
# @yield [ctx, buf] Passes the Digest and (maybe) the buffer
|
|
171
|
+
# @yieldparam ctx [Digest::Instance] The digest instance to the block
|
|
172
|
+
# @yieldparam buf [String, nil] The current read buffer (if +data+ is set)
|
|
173
|
+
# @yieldreturn [nil] The result of the block is ignored
|
|
174
|
+
#
|
|
175
|
+
# @return [URI::NI]
|
|
166
176
|
def self.compute data = nil, algorithm: :"sha-256", blocksize: 65536,
|
|
167
177
|
authority: nil, query: nil, &block
|
|
168
178
|
|
|
@@ -170,6 +180,21 @@ class URI::NI < URI::Generic
|
|
|
170
180
|
blocksize: blocksize, authority: authority, query: query, &block
|
|
171
181
|
end
|
|
172
182
|
|
|
183
|
+
# Return a Digest::Instance for a supported algorithm.
|
|
184
|
+
# @param [#to_s, #to_sym] The algorithm
|
|
185
|
+
# @return [Digest:Instance] The digest context
|
|
186
|
+
# @raise [ArgumentError] if the algorithm is unrecognized
|
|
187
|
+
def self.context algorithm
|
|
188
|
+
raise ArgumentError, "Cannot coerce #{algorithm} to a symbol" unless
|
|
189
|
+
algorithm.respond_to(:to_s) # cheat: symbols respond to to_s
|
|
190
|
+
algorithm = algorithm.to_s.to_sym unless algorithm.is_a? Symbol
|
|
191
|
+
raise ArgumentError, "Unsupported digest algorithm #{algorithm}" unless
|
|
192
|
+
ctx = DIGESTS[algorithm]
|
|
193
|
+
ctx.new
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# (Re)-compute a digest using existing information from an instance.
|
|
197
|
+
# @see .compute
|
|
173
198
|
def compute data = nil, algorithm: nil, blocksize: 65536,
|
|
174
199
|
authority: nil, query: nil, &block
|
|
175
200
|
|
|
@@ -186,7 +211,7 @@ class URI::NI < URI::Generic
|
|
|
186
211
|
data = nil # unset data
|
|
187
212
|
else
|
|
188
213
|
# make sure we're all on the same page hurr
|
|
189
|
-
self.algorithm = algorithm ||= self.algorithm
|
|
214
|
+
self.algorithm = algorithm ||= self.algorithm || :"sha-256"
|
|
190
215
|
raise URI::InvalidComponentError,
|
|
191
216
|
"Can't resolve a Digest context for the algorithm #{algorithm}." unless
|
|
192
217
|
ctx = DIGESTS[algorithm]
|
|
@@ -288,7 +313,7 @@ class URI::NI < URI::Generic
|
|
|
288
313
|
|
|
289
314
|
# Set the digest to the data, with an optional radix. Data may
|
|
290
315
|
# either be a +Digest::Instance+—in which case the radix is
|
|
291
|
-
# ignored
|
|
316
|
+
# ignored—a string, or +nil+. +Digest::Instance+ objects will
|
|
292
317
|
# just be run through #compute, with all that entails.
|
|
293
318
|
#
|
|
294
319
|
# @param value [String, nil, Digest::Instance] The new digest
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uri-ni
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Taylor
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-01-
|
|
11
|
+
date: 2020-01-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|