uri-ni 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/ni-uri +40 -0
- data/lib/uri/ni.rb +13 -1
- data/lib/uri/ni/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1c4325ac19a7451179586b13811dab241ea0ea6ecb5d5e655193a4b1780e3b0
|
4
|
+
data.tar.gz: b3318a52162366d7887619c7b2b60727f5b43c6624960e61affaad53b6a25121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9892531f60b96df7e275f5ec5b5b2e9088166bf40883363a40f3002b47af05ca7905e287f2251d00689305b97f6f2e0f70fec7ef28f86c7a1b03c43b7ddf9928
|
7
|
+
data.tar.gz: 1c390012d6210ea3b02798eedd22f2d3a920c0961d458b06487f6a52002924bd9007139f142fb6255a0afe652c64e30b032882795138cdadb55457af1c16da26
|
data/exe/ni-uri
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: enh-ruby -*-
|
3
|
+
|
4
|
+
require 'uri/ni'
|
5
|
+
require 'pathname'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
op = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: ni-uri [options] FILES"
|
11
|
+
|
12
|
+
opts.on("-a", "--algorithm STRING", "algorithm") do |a|
|
13
|
+
options[:algorithm] = a.to_sym
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
op.parse!
|
18
|
+
|
19
|
+
options[:algorithm] ||= :"sha-256"
|
20
|
+
unless URI::NI.valid_algo? options[:algorithm]
|
21
|
+
$stderr.puts "#{options[:algorithm]} is not a valid algorithm"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
if ARGV.empty?
|
26
|
+
puts op.to_s
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
ARGV.each do |fn|
|
31
|
+
fn = Pathname(fn).expand_path
|
32
|
+
begin
|
33
|
+
fh = fn.open
|
34
|
+
ni = URI::NI.compute fh, algorithm: options[:algorithm]
|
35
|
+
puts ni.to_s
|
36
|
+
rescue SystemCallError => e
|
37
|
+
$stderr.puts "Could not compute digest for #{fn}: #{e.message}"
|
38
|
+
next
|
39
|
+
end
|
40
|
+
end
|
data/lib/uri/ni.rb
CHANGED
@@ -186,7 +186,7 @@ class URI::NI < URI::Generic
|
|
186
186
|
# @raise [ArgumentError] if the algorithm is unrecognized
|
187
187
|
def self.context algorithm
|
188
188
|
raise ArgumentError, "Cannot coerce #{algorithm} to a symbol" unless
|
189
|
-
algorithm.respond_to
|
189
|
+
algorithm.respond_to? :to_s # cheat: symbols respond to to_s
|
190
190
|
algorithm = algorithm.to_s.to_sym unless algorithm.is_a? Symbol
|
191
191
|
raise ArgumentError, "Unsupported digest algorithm #{algorithm}" unless
|
192
192
|
ctx = DIGESTS[algorithm]
|
@@ -475,4 +475,16 @@ class URI::NI < URI::Generic
|
|
475
475
|
to_www https: false, authority: authority
|
476
476
|
end
|
477
477
|
|
478
|
+
# Returns the set of supported algorithms.
|
479
|
+
# @return [Array] the algorithms
|
480
|
+
def self.algorithms
|
481
|
+
DIGESTS.keys
|
482
|
+
end
|
483
|
+
|
484
|
+
# Returns true if the algorithm is supported.
|
485
|
+
# @param algorithm [Symbol,String] the algorithm identifier to test
|
486
|
+
# @return [true, false] whether it is supported
|
487
|
+
def self.valid_algo? algorithm
|
488
|
+
DIGESTS.has_key? algorithm.to_s.downcase.to_sym
|
489
|
+
end
|
478
490
|
end
|
data/lib/uri/ni/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.4
|
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-
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -41,7 +41,8 @@ dependencies:
|
|
41
41
|
description: ''
|
42
42
|
email:
|
43
43
|
- code@doriantaylor.com
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- ni-uri
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
@@ -54,6 +55,7 @@ files:
|
|
54
55
|
- Rakefile
|
55
56
|
- bin/console
|
56
57
|
- bin/setup
|
58
|
+
- exe/ni-uri
|
57
59
|
- lib/uri-ni.rb
|
58
60
|
- lib/uri/ni.rb
|
59
61
|
- lib/uri/ni/version.rb
|