uri-ni 0.2.1 → 0.2.3
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 +48 -10
- 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: 72fad83584f69d2982732c3a0578e6a19a740b4aab3892b5d80e0a73f97b3e9e
|
|
4
|
+
data.tar.gz: 94e56f2e88436acb04627be6d8b5b87f3a357dd0c1828ef3569ccdda21541812
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1d00ea6cb3b0b5dadac6097871743c4f4e709f884093dafd488c8e2a3d0bc2beae7e48c6bf54db509380137a671f0705abf464e18f41a43bbc7cd9500fe7f640
|
|
7
|
+
data.tar.gz: bd0774e708e1ec4f5b570a1770bb12363520282e802705ce4b76b2235d186e089c42773374388f56f71c5d6c1ae8958fe95e63a2435410d7191c37dd401b2a24
|
data/lib/uri/ni/version.rb
CHANGED
data/lib/uri/ni.rb
CHANGED
|
@@ -58,7 +58,9 @@ class URI::NI < URI::Generic
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
[k, v]
|
|
61
|
-
end.to_h
|
|
61
|
+
end.to_h.freeze
|
|
62
|
+
|
|
63
|
+
TRUNCATED = [32, 64, 96, 120, 128].map { |i| "sha-256-#{i}".to_sym }.freeze
|
|
62
64
|
|
|
63
65
|
# resolve first against digest length and then class
|
|
64
66
|
DIGEST_REV = {
|
|
@@ -324,18 +326,28 @@ class URI::NI < URI::Generic
|
|
|
324
326
|
LENGTHS[algorithm] and LENGTHS[algorithm] == digest.length
|
|
325
327
|
end
|
|
326
328
|
|
|
329
|
+
# Returns true if the algorithm is a truncated one.
|
|
330
|
+
#
|
|
331
|
+
# @return [false, true]
|
|
332
|
+
#
|
|
333
|
+
def truncated?
|
|
334
|
+
TRUNCATED.include? algorithm
|
|
335
|
+
end
|
|
336
|
+
|
|
327
337
|
# Display the available algorithms.
|
|
328
338
|
#
|
|
329
339
|
# @return [Array] containing the symbols representing the available
|
|
330
340
|
# digest algorithms.
|
|
341
|
+
#
|
|
331
342
|
def self.algorithms truncated: false
|
|
332
343
|
out = DIGESTS.keys.sort
|
|
333
|
-
truncated ? out : out
|
|
344
|
+
truncated ? out : out - TRUNCATED
|
|
334
345
|
end
|
|
335
346
|
|
|
336
347
|
# Obtain the algorithm of the digest. May be nil.
|
|
337
348
|
#
|
|
338
349
|
# @return [Symbol, nil]
|
|
350
|
+
#
|
|
339
351
|
def algorithm
|
|
340
352
|
algo = assert_path.first
|
|
341
353
|
return algo.to_sym if algo
|
|
@@ -343,7 +355,8 @@ class URI::NI < URI::Generic
|
|
|
343
355
|
|
|
344
356
|
# Set the algorithm of the digest. Will croak if the path is malformed.
|
|
345
357
|
#
|
|
346
|
-
# @return [Symbol, nil]
|
|
358
|
+
# @return [Symbol, nil]
|
|
359
|
+
#
|
|
347
360
|
def algorithm= algo
|
|
348
361
|
a, b = assert_path
|
|
349
362
|
self.path = "/#{algo}"
|
|
@@ -354,6 +367,7 @@ class URI::NI < URI::Generic
|
|
|
354
367
|
# Obtain the authority (userinfo@host:port) if present.
|
|
355
368
|
#
|
|
356
369
|
# @return [String, nil] the authority
|
|
370
|
+
#
|
|
357
371
|
def authority
|
|
358
372
|
out = userinfo ? "#{userinfo}@#{host}" : host
|
|
359
373
|
out += "#{out}:#{port}" if port
|
|
@@ -362,7 +376,8 @@ class URI::NI < URI::Generic
|
|
|
362
376
|
|
|
363
377
|
# Set the authority of the URI.
|
|
364
378
|
#
|
|
365
|
-
# @return [String, nil]
|
|
379
|
+
# @return [String, nil]
|
|
380
|
+
#
|
|
366
381
|
def authority= authority
|
|
367
382
|
old = self.authority
|
|
368
383
|
u, h, p = assert_authority authority unless authority.nil?
|
|
@@ -383,6 +398,7 @@ class URI::NI < URI::Generic
|
|
|
383
398
|
#
|
|
384
399
|
# @param radix [256, 64, 32, 16] The radix of the representation
|
|
385
400
|
# @param alt [false, true] Return the alternative representation
|
|
401
|
+
#
|
|
386
402
|
# @return [String] The digest of the URI in the given representation
|
|
387
403
|
#
|
|
388
404
|
def digest radix: 256, alt: false
|
|
@@ -397,6 +413,7 @@ class URI::NI < URI::Generic
|
|
|
397
413
|
#
|
|
398
414
|
# @param value [String, nil, Digest::Instance] The new digest
|
|
399
415
|
# @param radix [256, 64, 32, 16] The radix of the encoding (default 256)
|
|
416
|
+
#
|
|
400
417
|
# @return [String] The _old_ digest in the given radix
|
|
401
418
|
#
|
|
402
419
|
def set_digest value, radix: 256
|
|
@@ -430,6 +447,7 @@ class URI::NI < URI::Generic
|
|
|
430
447
|
# objects will just be run through #compute, with all that entails.
|
|
431
448
|
#
|
|
432
449
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
450
|
+
#
|
|
433
451
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
434
452
|
#
|
|
435
453
|
def digest= value
|
|
@@ -441,6 +459,7 @@ class URI::NI < URI::Generic
|
|
|
441
459
|
# representation.
|
|
442
460
|
#
|
|
443
461
|
# @param alt [false, true] Return the alternative representation
|
|
462
|
+
#
|
|
444
463
|
# @return [String] The hexadecimal digest
|
|
445
464
|
#
|
|
446
465
|
def hexdigest alt: false
|
|
@@ -448,8 +467,11 @@ class URI::NI < URI::Generic
|
|
|
448
467
|
end
|
|
449
468
|
|
|
450
469
|
# Set the digest value, assuming a hexadecimal input.
|
|
470
|
+
#
|
|
451
471
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
472
|
+
#
|
|
452
473
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
474
|
+
#
|
|
453
475
|
def hexdigest= value
|
|
454
476
|
set_digest value, radix: 16
|
|
455
477
|
end
|
|
@@ -459,6 +481,7 @@ class URI::NI < URI::Generic
|
|
|
459
481
|
# representation. Note this method requires the base32 module.
|
|
460
482
|
#
|
|
461
483
|
# @param alt [false, true] Return the alternative representation
|
|
484
|
+
#
|
|
462
485
|
# @return [String] The base32 digest
|
|
463
486
|
#
|
|
464
487
|
def b32digest alt: false
|
|
@@ -466,8 +489,11 @@ class URI::NI < URI::Generic
|
|
|
466
489
|
end
|
|
467
490
|
|
|
468
491
|
# Set the digest value, assuming a base32 input (requires base32).
|
|
492
|
+
#
|
|
469
493
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
494
|
+
#
|
|
470
495
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
496
|
+
#
|
|
471
497
|
def b32digest= value
|
|
472
498
|
set_digest value, radix: 32
|
|
473
499
|
end
|
|
@@ -478,6 +504,7 @@ class URI::NI < URI::Generic
|
|
|
478
504
|
# (_non_-URL-safe) base64 representation.
|
|
479
505
|
#
|
|
480
506
|
# @param alt [false, true] Return the alternative representation
|
|
507
|
+
#
|
|
481
508
|
# @return [String] The base64 digest
|
|
482
509
|
#
|
|
483
510
|
def b64digest alt: false
|
|
@@ -485,8 +512,11 @@ class URI::NI < URI::Generic
|
|
|
485
512
|
end
|
|
486
513
|
|
|
487
514
|
# Set the digest value, assuming a base64 input.
|
|
515
|
+
#
|
|
488
516
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
517
|
+
#
|
|
489
518
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
519
|
+
#
|
|
490
520
|
def b64digest= value
|
|
491
521
|
set_digest value, radix: 64
|
|
492
522
|
end
|
|
@@ -496,6 +526,7 @@ class URI::NI < URI::Generic
|
|
|
496
526
|
#
|
|
497
527
|
# @param authority [#to_s, URI] Override the authority part of the URI
|
|
498
528
|
# @param https [true, false] Whether the URL is to be HTTPS.
|
|
529
|
+
#
|
|
499
530
|
# @return [URI::HTTPS, URI::HTTP] The generated URL.
|
|
500
531
|
#
|
|
501
532
|
def to_www https: true, authority: nil
|
|
@@ -541,6 +572,7 @@ class URI::NI < URI::Generic
|
|
|
541
572
|
# Unconditionally returns an HTTPS URL.
|
|
542
573
|
#
|
|
543
574
|
# @param authority [#to_s, URI] Override the authority part of the URI
|
|
575
|
+
#
|
|
544
576
|
# @return [URI::HTTPS]
|
|
545
577
|
#
|
|
546
578
|
def to_https authority: nil
|
|
@@ -551,6 +583,7 @@ class URI::NI < URI::Generic
|
|
|
551
583
|
# Unconditionally returns an HTTP URL.
|
|
552
584
|
#
|
|
553
585
|
# @param authority [#to_s, URI] Override the authority part of the URI
|
|
586
|
+
#
|
|
554
587
|
# @return [URI::HTTP]
|
|
555
588
|
#
|
|
556
589
|
def to_http authority: nil
|
|
@@ -559,15 +592,20 @@ class URI::NI < URI::Generic
|
|
|
559
592
|
|
|
560
593
|
|
|
561
594
|
# Returns true if the algorithm is supported.
|
|
595
|
+
#
|
|
562
596
|
# @param algorithm [Symbol,String] the algorithm identifier to test
|
|
597
|
+
#
|
|
563
598
|
# @return [true, false] whether it is supported
|
|
599
|
+
#
|
|
564
600
|
def self.valid_algo? algorithm
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
# special case for truncated sha-256
|
|
568
|
-
return true if /^(sha-256)-(32|64|96|120|128)$/.match? algorithm
|
|
601
|
+
DIGESTS.has_key? algorithm.to_s.downcase.to_sym
|
|
602
|
+
end
|
|
569
603
|
|
|
570
|
-
|
|
571
|
-
|
|
604
|
+
# Returns true if the supplied algorithm is a truncated one.
|
|
605
|
+
#
|
|
606
|
+
# @return [false, true]
|
|
607
|
+
#
|
|
608
|
+
def self.truncated? algorithm
|
|
609
|
+
valid_algo?(algorithm) && TRUNCATED.include?(algorithm.to_s.downcase.to_sym)
|
|
572
610
|
end
|
|
573
611
|
end
|