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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/uri/ni/version.rb +1 -1
  3. data/lib/uri/ni.rb +28 -3
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eff8af7f69a76b24ce06948c53ad963d39552ec2dee0b08179496a1a8eb5d2a1
4
- data.tar.gz: d7d285ac8eb47acf9acd0cd3de7dbcad6110c9e80f1860817534b18c1e25d87c
3
+ metadata.gz: e205294ee6b137c97fca41dfe3017b8fcfe41e28ba949002ba00167d216c3dd8
4
+ data.tar.gz: d81cbabc67dc1ed564d790232011119e1b3eec87044531680e6db77f2bc728a6
5
5
  SHA512:
6
- metadata.gz: 4bbdf0f3d6fd23db734e13403e20d96f6e29730c43f93351556a47ab10250508b743497c02870bcb7447d643e31254686a889277e5bbf10941caef329b6b71d2
7
- data.tar.gz: b777dc59e94aff9e947cfd4661b64aecc727baeae4a2c5cc14fed58c8b59fd4495bb6ae935864a2e61a8fb9dbb86098e3665475baa2c59127975d97b734f5046
6
+ metadata.gz: 85745faf2e879e90a233f60f937b9f55adcfcca2cb06e4871ebfab119ba98bc88517b8907baafb50412cbdd6af7342dbdadc1f0652382ad96a614cd64084b56c
7
+ data.tar.gz: fe3bd0a1fef2939489dc31dc463e7038f632a771f0d9feb17b72617c37bc19cfae78eb19d304b7f06f85694114ea6cafb34d0065e664147c9516bd0078cfe97e
@@ -3,7 +3,7 @@ require 'uri/generic'
3
3
 
4
4
  module URI
5
5
  class NI < Generic
6
- VERSION = "0.1.1"
6
+ VERSION = "0.1.2"
7
7
  end
8
8
 
9
9
  # might as well put this here
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
- # ignoreda string, or +nil+. +Digest::Instance+ objects will
316
+ # ignoreda 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.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-06 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler