uri-ni 0.2.0 → 0.2.1
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 +41 -13
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7f97e35f7fc6987d8051e1f09e23cc2cbc29b6e188496b5d1abd5d030a7ec32
|
|
4
|
+
data.tar.gz: 3a66e3863206978a52e1281318808f043de2b7e4409b09d8bdff37a589bfb3fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eac81311c6e7e895c908b0d45db5a7b028ed1e9b2e1b65e35d264c5840837abc589a9c11ac315272bf751f1f326b753f1b5e2f1add14313ae66258eefeee7c88
|
|
7
|
+
data.tar.gz: 8456780c695e1ad060546e46bf8cc1fcccbee00c1d535e6a3845f19f2928fd1a13efb720e264f23091fcf24b82bae797365877ca3747d6701502f96df61c65ca
|
data/lib/uri/ni/version.rb
CHANGED
data/lib/uri/ni.rb
CHANGED
|
@@ -42,9 +42,23 @@ class URI::NI < URI::Generic
|
|
|
42
42
|
"sha-256": Digest::SHA256,
|
|
43
43
|
"sha-384": Digest::SHA384,
|
|
44
44
|
"sha-512": Digest::SHA512,
|
|
45
|
+
# XXX not sure if i want to do this
|
|
46
|
+
"sha-256-32": Digest::SHA256,
|
|
47
|
+
"sha-256-64": Digest::SHA256,
|
|
48
|
+
"sha-256-96": Digest::SHA256,
|
|
49
|
+
"sha-256-120": Digest::SHA256,
|
|
50
|
+
"sha-256-128": Digest::SHA256,
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
LENGTHS = DIGESTS.
|
|
53
|
+
LENGTHS = DIGESTS.map do |k, v|
|
|
54
|
+
v = if m = /^sha-256-(\d+)$/.match(k)
|
|
55
|
+
m.captures.first.to_i / 8
|
|
56
|
+
else
|
|
57
|
+
v.new.digest_length
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
[k, v]
|
|
61
|
+
end.to_h
|
|
48
62
|
|
|
49
63
|
# resolve first against digest length and then class
|
|
50
64
|
DIGEST_REV = {
|
|
@@ -261,7 +275,8 @@ class URI::NI < URI::Generic
|
|
|
261
275
|
# special case for when the data is a digest
|
|
262
276
|
ctx = nil
|
|
263
277
|
if data.is_a? Digest::Instance
|
|
264
|
-
|
|
278
|
+
# note the self; this would have been a bug lol
|
|
279
|
+
self.algorithm = algorithm ||= algo_for data, algorithm
|
|
265
280
|
ctx = data
|
|
266
281
|
data = nil # unset data
|
|
267
282
|
else
|
|
@@ -296,17 +311,26 @@ class URI::NI < URI::Generic
|
|
|
296
311
|
block.call ctx, nil
|
|
297
312
|
end
|
|
298
313
|
|
|
299
|
-
|
|
300
|
-
|
|
314
|
+
set_digest ctx.digest
|
|
315
|
+
|
|
301
316
|
self
|
|
302
317
|
end
|
|
303
318
|
|
|
319
|
+
# Returns true if the digest length matches the algorithm.
|
|
320
|
+
#
|
|
321
|
+
# @return [false, true]
|
|
322
|
+
#
|
|
323
|
+
def valid?
|
|
324
|
+
LENGTHS[algorithm] and LENGTHS[algorithm] == digest.length
|
|
325
|
+
end
|
|
326
|
+
|
|
304
327
|
# Display the available algorithms.
|
|
305
328
|
#
|
|
306
329
|
# @return [Array] containing the symbols representing the available
|
|
307
330
|
# digest algorithms.
|
|
308
|
-
def self.algorithms
|
|
309
|
-
DIGESTS.keys.sort
|
|
331
|
+
def self.algorithms truncated: false
|
|
332
|
+
out = DIGESTS.keys.sort
|
|
333
|
+
truncated ? out : out.reject { |a| /^sha-256-/.match? a }
|
|
310
334
|
end
|
|
311
335
|
|
|
312
336
|
# Obtain the algorithm of the digest. May be nil.
|
|
@@ -384,7 +408,10 @@ class URI::NI < URI::Generic
|
|
|
384
408
|
when Digest::Instance
|
|
385
409
|
compute value
|
|
386
410
|
when String
|
|
387
|
-
value = transcode value, from: radix
|
|
411
|
+
value = transcode value, from: radix
|
|
412
|
+
value = value[0, LENGTHS[a.to_sym]] # deal with truncation
|
|
413
|
+
value = transcode value, to: 64
|
|
414
|
+
|
|
388
415
|
self.path = a ? "/#{a};#{value}" : "/;#{value}"
|
|
389
416
|
when nil
|
|
390
417
|
self.path = a ? "/#{a}" : ?/
|
|
@@ -530,16 +557,17 @@ class URI::NI < URI::Generic
|
|
|
530
557
|
to_www https: false, authority: authority
|
|
531
558
|
end
|
|
532
559
|
|
|
533
|
-
# Returns the set of supported algorithms.
|
|
534
|
-
# @return [Array] the algorithms
|
|
535
|
-
def self.algorithms
|
|
536
|
-
DIGESTS.keys
|
|
537
|
-
end
|
|
538
560
|
|
|
539
561
|
# Returns true if the algorithm is supported.
|
|
540
562
|
# @param algorithm [Symbol,String] the algorithm identifier to test
|
|
541
563
|
# @return [true, false] whether it is supported
|
|
542
564
|
def self.valid_algo? algorithm
|
|
543
|
-
|
|
565
|
+
algorithm = algorithm.to_s.downcase.to_sym
|
|
566
|
+
|
|
567
|
+
# special case for truncated sha-256
|
|
568
|
+
return true if /^(sha-256)-(32|64|96|120|128)$/.match? algorithm
|
|
569
|
+
|
|
570
|
+
# etc
|
|
571
|
+
DIGESTS.has_key? algorithm
|
|
544
572
|
end
|
|
545
573
|
end
|