uri-ni 0.2.2 → 0.2.4
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 +55 -12
- 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: 6f21e8e7bf5c19fc3eedf94e5a41c401c8bf0c49153b70abf1ec27d301811c9c
|
|
4
|
+
data.tar.gz: 10db96336f2f2509b4079d295af3bac755ecfdc07d06c2fc43fbebb21ba95974
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 803def5e52f0265a7cbb881bb874e3d306f352b79f24eee939981591692dad450bb3be5d5f88de050939a8c37154531935401e6f8abf62a7886583b2ed8527ac
|
|
7
|
+
data.tar.gz: d9081a72a683c62a550c28bb19c0c713913a20addebfbb9e203bceb5a04262f982d841bd5d65b0e773722ab10c15ec99da12f88ce9b67734f0a25a27ab00b4fb
|
data/lib/uri/ni/version.rb
CHANGED
data/lib/uri/ni.rb
CHANGED
|
@@ -198,14 +198,29 @@ class URI::NI < URI::Generic
|
|
|
198
198
|
# @return [URI::NI] the transformed identifier
|
|
199
199
|
#
|
|
200
200
|
def self.ingest algorithm = nil, digest
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
if digest.is_a? Digest::Instance
|
|
202
|
+
# this will complain
|
|
203
|
+
algo_for digest, algorithm
|
|
204
|
+
return compute(digest)
|
|
205
|
+
elsif digest.is_a? URI::NI
|
|
206
|
+
raise ArgumentError,
|
|
207
|
+
"digest algorithm #{digest.algorithm} does not match #{algorithm}" if
|
|
208
|
+
algorithm && algorithm != digest.algorithm
|
|
209
|
+
return digest
|
|
210
|
+
end
|
|
203
211
|
|
|
204
212
|
# make sure we're indeed dealing with a string
|
|
205
213
|
digest = digest.to_s
|
|
206
214
|
|
|
207
215
|
# just parse if it's already a ni: URI string
|
|
208
|
-
|
|
216
|
+
if /^ni:/i.match? digest
|
|
217
|
+
digest = URI(digest)
|
|
218
|
+
raise ArgumentError,
|
|
219
|
+
"digest algorithm #{digest.algorithm} does not match #{algorithm}" if
|
|
220
|
+
algorithm && algorithm != digest.algorithm
|
|
221
|
+
|
|
222
|
+
return digest
|
|
223
|
+
end
|
|
209
224
|
|
|
210
225
|
# get the expected length of the digest for the algorithm
|
|
211
226
|
len = LENGTHS[algorithm.to_s.downcase.to_sym] or raise ArgumentError,
|
|
@@ -338,14 +353,16 @@ class URI::NI < URI::Generic
|
|
|
338
353
|
#
|
|
339
354
|
# @return [Array] containing the symbols representing the available
|
|
340
355
|
# digest algorithms.
|
|
356
|
+
#
|
|
341
357
|
def self.algorithms truncated: false
|
|
342
358
|
out = DIGESTS.keys.sort
|
|
343
|
-
truncated ? out : out
|
|
359
|
+
truncated ? out : out - TRUNCATED
|
|
344
360
|
end
|
|
345
361
|
|
|
346
362
|
# Obtain the algorithm of the digest. May be nil.
|
|
347
363
|
#
|
|
348
364
|
# @return [Symbol, nil]
|
|
365
|
+
#
|
|
349
366
|
def algorithm
|
|
350
367
|
algo = assert_path.first
|
|
351
368
|
return algo.to_sym if algo
|
|
@@ -353,7 +370,8 @@ class URI::NI < URI::Generic
|
|
|
353
370
|
|
|
354
371
|
# Set the algorithm of the digest. Will croak if the path is malformed.
|
|
355
372
|
#
|
|
356
|
-
# @return [Symbol, nil]
|
|
373
|
+
# @return [Symbol, nil]
|
|
374
|
+
#
|
|
357
375
|
def algorithm= algo
|
|
358
376
|
a, b = assert_path
|
|
359
377
|
self.path = "/#{algo}"
|
|
@@ -364,6 +382,7 @@ class URI::NI < URI::Generic
|
|
|
364
382
|
# Obtain the authority (userinfo@host:port) if present.
|
|
365
383
|
#
|
|
366
384
|
# @return [String, nil] the authority
|
|
385
|
+
#
|
|
367
386
|
def authority
|
|
368
387
|
out = userinfo ? "#{userinfo}@#{host}" : host
|
|
369
388
|
out += "#{out}:#{port}" if port
|
|
@@ -372,7 +391,8 @@ class URI::NI < URI::Generic
|
|
|
372
391
|
|
|
373
392
|
# Set the authority of the URI.
|
|
374
393
|
#
|
|
375
|
-
# @return [String, nil]
|
|
394
|
+
# @return [String, nil]
|
|
395
|
+
#
|
|
376
396
|
def authority= authority
|
|
377
397
|
old = self.authority
|
|
378
398
|
u, h, p = assert_authority authority unless authority.nil?
|
|
@@ -393,6 +413,7 @@ class URI::NI < URI::Generic
|
|
|
393
413
|
#
|
|
394
414
|
# @param radix [256, 64, 32, 16] The radix of the representation
|
|
395
415
|
# @param alt [false, true] Return the alternative representation
|
|
416
|
+
#
|
|
396
417
|
# @return [String] The digest of the URI in the given representation
|
|
397
418
|
#
|
|
398
419
|
def digest radix: 256, alt: false
|
|
@@ -407,6 +428,7 @@ class URI::NI < URI::Generic
|
|
|
407
428
|
#
|
|
408
429
|
# @param value [String, nil, Digest::Instance] The new digest
|
|
409
430
|
# @param radix [256, 64, 32, 16] The radix of the encoding (default 256)
|
|
431
|
+
#
|
|
410
432
|
# @return [String] The _old_ digest in the given radix
|
|
411
433
|
#
|
|
412
434
|
def set_digest value, radix: 256
|
|
@@ -440,6 +462,7 @@ class URI::NI < URI::Generic
|
|
|
440
462
|
# objects will just be run through #compute, with all that entails.
|
|
441
463
|
#
|
|
442
464
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
465
|
+
#
|
|
443
466
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
444
467
|
#
|
|
445
468
|
def digest= value
|
|
@@ -451,6 +474,7 @@ class URI::NI < URI::Generic
|
|
|
451
474
|
# representation.
|
|
452
475
|
#
|
|
453
476
|
# @param alt [false, true] Return the alternative representation
|
|
477
|
+
#
|
|
454
478
|
# @return [String] The hexadecimal digest
|
|
455
479
|
#
|
|
456
480
|
def hexdigest alt: false
|
|
@@ -458,8 +482,11 @@ class URI::NI < URI::Generic
|
|
|
458
482
|
end
|
|
459
483
|
|
|
460
484
|
# Set the digest value, assuming a hexadecimal input.
|
|
485
|
+
#
|
|
461
486
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
487
|
+
#
|
|
462
488
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
489
|
+
#
|
|
463
490
|
def hexdigest= value
|
|
464
491
|
set_digest value, radix: 16
|
|
465
492
|
end
|
|
@@ -469,6 +496,7 @@ class URI::NI < URI::Generic
|
|
|
469
496
|
# representation. Note this method requires the base32 module.
|
|
470
497
|
#
|
|
471
498
|
# @param alt [false, true] Return the alternative representation
|
|
499
|
+
#
|
|
472
500
|
# @return [String] The base32 digest
|
|
473
501
|
#
|
|
474
502
|
def b32digest alt: false
|
|
@@ -476,8 +504,11 @@ class URI::NI < URI::Generic
|
|
|
476
504
|
end
|
|
477
505
|
|
|
478
506
|
# Set the digest value, assuming a base32 input (requires base32).
|
|
507
|
+
#
|
|
479
508
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
509
|
+
#
|
|
480
510
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
511
|
+
#
|
|
481
512
|
def b32digest= value
|
|
482
513
|
set_digest value, radix: 32
|
|
483
514
|
end
|
|
@@ -488,6 +519,7 @@ class URI::NI < URI::Generic
|
|
|
488
519
|
# (_non_-URL-safe) base64 representation.
|
|
489
520
|
#
|
|
490
521
|
# @param alt [false, true] Return the alternative representation
|
|
522
|
+
#
|
|
491
523
|
# @return [String] The base64 digest
|
|
492
524
|
#
|
|
493
525
|
def b64digest alt: false
|
|
@@ -495,8 +527,11 @@ class URI::NI < URI::Generic
|
|
|
495
527
|
end
|
|
496
528
|
|
|
497
529
|
# Set the digest value, assuming a base64 input.
|
|
530
|
+
#
|
|
498
531
|
# @param value [String, nil, Digest::Instance] the new digest
|
|
532
|
+
#
|
|
499
533
|
# @return [String, nil, Digest::Instance] the value passed in
|
|
534
|
+
#
|
|
500
535
|
def b64digest= value
|
|
501
536
|
set_digest value, radix: 64
|
|
502
537
|
end
|
|
@@ -506,6 +541,7 @@ class URI::NI < URI::Generic
|
|
|
506
541
|
#
|
|
507
542
|
# @param authority [#to_s, URI] Override the authority part of the URI
|
|
508
543
|
# @param https [true, false] Whether the URL is to be HTTPS.
|
|
544
|
+
#
|
|
509
545
|
# @return [URI::HTTPS, URI::HTTP] The generated URL.
|
|
510
546
|
#
|
|
511
547
|
def to_www https: true, authority: nil
|
|
@@ -551,6 +587,7 @@ class URI::NI < URI::Generic
|
|
|
551
587
|
# Unconditionally returns an HTTPS URL.
|
|
552
588
|
#
|
|
553
589
|
# @param authority [#to_s, URI] Override the authority part of the URI
|
|
590
|
+
#
|
|
554
591
|
# @return [URI::HTTPS]
|
|
555
592
|
#
|
|
556
593
|
def to_https authority: nil
|
|
@@ -561,6 +598,7 @@ class URI::NI < URI::Generic
|
|
|
561
598
|
# Unconditionally returns an HTTP URL.
|
|
562
599
|
#
|
|
563
600
|
# @param authority [#to_s, URI] Override the authority part of the URI
|
|
601
|
+
#
|
|
564
602
|
# @return [URI::HTTP]
|
|
565
603
|
#
|
|
566
604
|
def to_http authority: nil
|
|
@@ -569,15 +607,20 @@ class URI::NI < URI::Generic
|
|
|
569
607
|
|
|
570
608
|
|
|
571
609
|
# Returns true if the algorithm is supported.
|
|
610
|
+
#
|
|
572
611
|
# @param algorithm [Symbol,String] the algorithm identifier to test
|
|
612
|
+
#
|
|
573
613
|
# @return [true, false] whether it is supported
|
|
614
|
+
#
|
|
574
615
|
def self.valid_algo? algorithm
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
# special case for truncated sha-256
|
|
578
|
-
return true if /^(sha-256)-(32|64|96|120|128)$/.match? algorithm
|
|
616
|
+
DIGESTS.has_key? algorithm.to_s.downcase.to_sym
|
|
617
|
+
end
|
|
579
618
|
|
|
580
|
-
|
|
581
|
-
|
|
619
|
+
# Returns true if the supplied algorithm is a truncated one.
|
|
620
|
+
#
|
|
621
|
+
# @return [false, true]
|
|
622
|
+
#
|
|
623
|
+
def self.truncated? algorithm
|
|
624
|
+
valid_algo?(algorithm) && TRUNCATED.include?(algorithm.to_s.downcase.to_sym)
|
|
582
625
|
end
|
|
583
626
|
end
|