uri-ni 0.2.2 → 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.
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 +37 -9
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0210a945c627b9ec4a14f96b5beac95ca2084e5a873643ed963d37f939f81796
4
- data.tar.gz: d3c7a53b7c0dfb92e64e2989114863838dbf2b895a9fb0a4375f86213fd61d7d
3
+ metadata.gz: 72fad83584f69d2982732c3a0578e6a19a740b4aab3892b5d80e0a73f97b3e9e
4
+ data.tar.gz: 94e56f2e88436acb04627be6d8b5b87f3a357dd0c1828ef3569ccdda21541812
5
5
  SHA512:
6
- metadata.gz: e02348cfcdb25c10a8ff83c462bfff0c3720b1488bedc33a3e8735eb1a98f3887afd50ca5d6f6674f30fd2ae92e3f5bf49822dbcc2ee6c1ee51385e55612ea36
7
- data.tar.gz: 4f6a9d14efab6c9b6fa46c9df390d5222ef8a8a6afe4d06aeba6709284d59f20d35aa12d5da4f8f3dc52cb2a159dd17f97872165278324b0407b20f8e4280bd7
6
+ metadata.gz: 1d00ea6cb3b0b5dadac6097871743c4f4e709f884093dafd488c8e2a3d0bc2beae7e48c6bf54db509380137a671f0705abf464e18f41a43bbc7cd9500fe7f640
7
+ data.tar.gz: bd0774e708e1ec4f5b570a1770bb12363520282e802705ce4b76b2235d186e089c42773374388f56f71c5d6c1ae8958fe95e63a2435410d7191c37dd401b2a24
@@ -3,7 +3,7 @@ require 'uri/generic'
3
3
 
4
4
  module URI
5
5
  class NI < Generic
6
- VERSION = "0.2.2"
6
+ VERSION = "0.2.3"
7
7
  end
8
8
 
9
9
  # might as well put this here
data/lib/uri/ni.rb CHANGED
@@ -338,14 +338,16 @@ class URI::NI < URI::Generic
338
338
  #
339
339
  # @return [Array] containing the symbols representing the available
340
340
  # digest algorithms.
341
+ #
341
342
  def self.algorithms truncated: false
342
343
  out = DIGESTS.keys.sort
343
- truncated ? out : out.reject { |a| /^sha-256-/.match? a }
344
+ truncated ? out : out - TRUNCATED
344
345
  end
345
346
 
346
347
  # Obtain the algorithm of the digest. May be nil.
347
348
  #
348
349
  # @return [Symbol, nil]
350
+ #
349
351
  def algorithm
350
352
  algo = assert_path.first
351
353
  return algo.to_sym if algo
@@ -353,7 +355,8 @@ class URI::NI < URI::Generic
353
355
 
354
356
  # Set the algorithm of the digest. Will croak if the path is malformed.
355
357
  #
356
- # @return [Symbol, nil] the old algorithm
358
+ # @return [Symbol, nil]
359
+ #
357
360
  def algorithm= algo
358
361
  a, b = assert_path
359
362
  self.path = "/#{algo}"
@@ -364,6 +367,7 @@ class URI::NI < URI::Generic
364
367
  # Obtain the authority (userinfo@host:port) if present.
365
368
  #
366
369
  # @return [String, nil] the authority
370
+ #
367
371
  def authority
368
372
  out = userinfo ? "#{userinfo}@#{host}" : host
369
373
  out += "#{out}:#{port}" if port
@@ -372,7 +376,8 @@ class URI::NI < URI::Generic
372
376
 
373
377
  # Set the authority of the URI.
374
378
  #
375
- # @return [String, nil] the old authority
379
+ # @return [String, nil]
380
+ #
376
381
  def authority= authority
377
382
  old = self.authority
378
383
  u, h, p = assert_authority authority unless authority.nil?
@@ -393,6 +398,7 @@ class URI::NI < URI::Generic
393
398
  #
394
399
  # @param radix [256, 64, 32, 16] The radix of the representation
395
400
  # @param alt [false, true] Return the alternative representation
401
+ #
396
402
  # @return [String] The digest of the URI in the given representation
397
403
  #
398
404
  def digest radix: 256, alt: false
@@ -407,6 +413,7 @@ class URI::NI < URI::Generic
407
413
  #
408
414
  # @param value [String, nil, Digest::Instance] The new digest
409
415
  # @param radix [256, 64, 32, 16] The radix of the encoding (default 256)
416
+ #
410
417
  # @return [String] The _old_ digest in the given radix
411
418
  #
412
419
  def set_digest value, radix: 256
@@ -440,6 +447,7 @@ class URI::NI < URI::Generic
440
447
  # objects will just be run through #compute, with all that entails.
441
448
  #
442
449
  # @param value [String, nil, Digest::Instance] the new digest
450
+ #
443
451
  # @return [String, nil, Digest::Instance] the value passed in
444
452
  #
445
453
  def digest= value
@@ -451,6 +459,7 @@ class URI::NI < URI::Generic
451
459
  # representation.
452
460
  #
453
461
  # @param alt [false, true] Return the alternative representation
462
+ #
454
463
  # @return [String] The hexadecimal digest
455
464
  #
456
465
  def hexdigest alt: false
@@ -458,8 +467,11 @@ class URI::NI < URI::Generic
458
467
  end
459
468
 
460
469
  # Set the digest value, assuming a hexadecimal input.
470
+ #
461
471
  # @param value [String, nil, Digest::Instance] the new digest
472
+ #
462
473
  # @return [String, nil, Digest::Instance] the value passed in
474
+ #
463
475
  def hexdigest= value
464
476
  set_digest value, radix: 16
465
477
  end
@@ -469,6 +481,7 @@ class URI::NI < URI::Generic
469
481
  # representation. Note this method requires the base32 module.
470
482
  #
471
483
  # @param alt [false, true] Return the alternative representation
484
+ #
472
485
  # @return [String] The base32 digest
473
486
  #
474
487
  def b32digest alt: false
@@ -476,8 +489,11 @@ class URI::NI < URI::Generic
476
489
  end
477
490
 
478
491
  # Set the digest value, assuming a base32 input (requires base32).
492
+ #
479
493
  # @param value [String, nil, Digest::Instance] the new digest
494
+ #
480
495
  # @return [String, nil, Digest::Instance] the value passed in
496
+ #
481
497
  def b32digest= value
482
498
  set_digest value, radix: 32
483
499
  end
@@ -488,6 +504,7 @@ class URI::NI < URI::Generic
488
504
  # (_non_-URL-safe) base64 representation.
489
505
  #
490
506
  # @param alt [false, true] Return the alternative representation
507
+ #
491
508
  # @return [String] The base64 digest
492
509
  #
493
510
  def b64digest alt: false
@@ -495,8 +512,11 @@ class URI::NI < URI::Generic
495
512
  end
496
513
 
497
514
  # Set the digest value, assuming a base64 input.
515
+ #
498
516
  # @param value [String, nil, Digest::Instance] the new digest
517
+ #
499
518
  # @return [String, nil, Digest::Instance] the value passed in
519
+ #
500
520
  def b64digest= value
501
521
  set_digest value, radix: 64
502
522
  end
@@ -506,6 +526,7 @@ class URI::NI < URI::Generic
506
526
  #
507
527
  # @param authority [#to_s, URI] Override the authority part of the URI
508
528
  # @param https [true, false] Whether the URL is to be HTTPS.
529
+ #
509
530
  # @return [URI::HTTPS, URI::HTTP] The generated URL.
510
531
  #
511
532
  def to_www https: true, authority: nil
@@ -551,6 +572,7 @@ class URI::NI < URI::Generic
551
572
  # Unconditionally returns an HTTPS URL.
552
573
  #
553
574
  # @param authority [#to_s, URI] Override the authority part of the URI
575
+ #
554
576
  # @return [URI::HTTPS]
555
577
  #
556
578
  def to_https authority: nil
@@ -561,6 +583,7 @@ class URI::NI < URI::Generic
561
583
  # Unconditionally returns an HTTP URL.
562
584
  #
563
585
  # @param authority [#to_s, URI] Override the authority part of the URI
586
+ #
564
587
  # @return [URI::HTTP]
565
588
  #
566
589
  def to_http authority: nil
@@ -569,15 +592,20 @@ class URI::NI < URI::Generic
569
592
 
570
593
 
571
594
  # Returns true if the algorithm is supported.
595
+ #
572
596
  # @param algorithm [Symbol,String] the algorithm identifier to test
597
+ #
573
598
  # @return [true, false] whether it is supported
599
+ #
574
600
  def self.valid_algo? algorithm
575
- algorithm = algorithm.to_s.downcase.to_sym
576
-
577
- # special case for truncated sha-256
578
- return true if /^(sha-256)-(32|64|96|120|128)$/.match? algorithm
601
+ DIGESTS.has_key? algorithm.to_s.downcase.to_sym
602
+ end
579
603
 
580
- # etc
581
- DIGESTS.has_key? algorithm
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)
582
610
  end
583
611
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-ni
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor