iana-registry 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f0b36b671dfa652651a43af26dd9d0c9e1562e60b27ef2300a55171e2453d5d
4
+ data.tar.gz: c671a984f4c9f6ff59957c80450c767388f1c345bf0b1b9cc4b515eebaadf707
5
+ SHA512:
6
+ metadata.gz: fac6cbe9adae43dcf2eb1f004fd80501aff8d6e337b63db9ac50259bd770ab571a86073572aced4f70f390ad2f3087f4d78e8dd105c1e7f5da5611128e790333
7
+ data.tar.gz: e539b339266327806eddf0eeed36b8082c617f88a3c2b3b9a948268470d47bfb46e0db26b9852d70733a12f3dc2952d66a8333402f7e9226644a85a7b0b50405
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby -Ku
2
+ # coding: utf-8
3
+ require 'iana-registry.rb'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+
7
+ $options = OpenStruct.new
8
+ $options.squash_spans = ENV["TAG_REPORT_SQUASH_RANGES"] # backwards compat
9
+
10
+ begin
11
+ op = OptionParser.new do |opts|
12
+ opts.banner = "Usage: $0 [options]"
13
+ opts.version = Gem.loaded_specs["iana-registry"].version
14
+
15
+
16
+ opts.on("-s", "--[no-]squash-spans", "Show number of spans, not of individual values") do |v|
17
+ $options.squash_spans = v
18
+ end
19
+ end
20
+ op.parse!
21
+ rescue Exception => e
22
+ warn e
23
+ warn op
24
+ exit 1
25
+ end
26
+
27
+ RANGES = [24, 0x100, 0x10000, 0x100000000, 0x10000000000000000]
28
+ RANGE_COUNTS = [0] * 5
29
+ RANGE_UNASSIGNEDS = [0] * 5
30
+ RANGE_LABELS = [0, 1, 2, 4, 8].map {"1+#{_1}"}
31
+
32
+ reg = IANA::Registry::CBOR_TAGS.new
33
+
34
+ [[reg.assigneds, RANGE_COUNTS],
35
+ [reg.unassigneds, RANGE_UNASSIGNEDS]].each do |l, t|
36
+ l.each do |s, e|
37
+ r = RANGES.find_index { _1 > s }
38
+ t[r] += $options.squash_spans ? 1 : e - s + 1
39
+ end
40
+ end
41
+
42
+ ranges_count = 0
43
+
44
+ puts "range used % free total"
45
+ (0...5).each do |i|
46
+ total = RANGES[i] - (i == 0 ? 0 : RANGES[i-1])
47
+ ct = RANGE_COUNTS[i]
48
+ ranges_count += ct
49
+ ua = RANGE_UNASSIGNEDS[i]
50
+ if total != ct + ua && !$options.squash_spans
51
+ warn "** internal/IANA data error: total != ct + ua"
52
+ end
53
+ s = "%0#4.2f" % (ct*100.0/total)
54
+ puts "%d %s %5d %05s %20d %20d" % [i, RANGE_LABELS[i], ct, s, ua, total]
55
+ end
56
+
57
+ if $options.squash_spans
58
+ puts " ---"
59
+ puts "total: #{ranges_count} spans assigned"
60
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby -Ku
2
+ # coding: utf-8
3
+ require 'iana-registry.rb'
4
+
5
+ doc = IANA::Registry.load("dns-parameters")
6
+
7
+ DNS_RR = {}
8
+
9
+ REXML::XPath.each(doc.root,
10
+ "//xmlns:registry[@id='dns-parameters-4']/xmlns:record",
11
+ IANA::Registry::NS) do |x|
12
+ typ = x.elements['type'].text
13
+ value = x.elements['value'].text.to_i
14
+ semantics = x.elements['description'].text
15
+ if semantics && typ =~ /\A[-_A-Z0-9]+\z/
16
+ DNS_RR[typ.gsub("-", "_")] = value
17
+ end
18
+ end
19
+
20
+ puts DNS_RR.map { |t, v|
21
+ "RR_#{t} = #{v}\n" }
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "iana-registry"
3
+ s.version = "0.0.1"
4
+ s.summary = "provides generalized access to IANA registries."
5
+ s.description = %q{This gem provides generalized access to XML-based IANA registries.}
6
+ s.author = "Carsten Bormann"
7
+ s.email = "cabo@tzi.org"
8
+ s.license = "MIT"
9
+ s.test_files = Dir['test/**/*.rb']
10
+ s.files = Dir['lib/**/*.rb'] + %w(iana-registry.gemspec) + Dir['bin/**/*.rb']
11
+ s.executables = Dir['bin/**/*.rb'].map {|x| File.basename(x)}
12
+ s.required_ruby_version = '>= 2.7'
13
+
14
+ s.require_paths = ["lib"]
15
+ end
@@ -0,0 +1,56 @@
1
+ require 'open-uri'
2
+ begin
3
+ require 'open-uri/cached'
4
+ rescue ScriptError => e
5
+ $iana_no_caching = e
6
+ end
7
+ require 'rexml/document'
8
+
9
+ module IANA
10
+ module Registry
11
+ REG_URI_FORM = "https://www.iana.org/assignments/%s/%s.xml"
12
+ ACCEPT_XML = {"Accept" => "application/xml"}
13
+ NS = {"xmlns" => "http://www.iana.org/assignments"}
14
+
15
+ def self.load(name)
16
+ uri = REG_URI_FORM % [name, name]
17
+ xml_src = URI(uri).open(ACCEPT_XML).read
18
+ REXML::Document.new(xml_src)
19
+ end
20
+
21
+ def self.warn_if_no_caching
22
+ warn "** URI caching not installed: #$iana_no_caching" if $iana_no_caching
23
+ end
24
+
25
+
26
+ class CBOR_TAGS
27
+ attr_reader :doc, :assigneds, :unassigneds
28
+
29
+ def initialize
30
+ @doc = IANA::Registry.load("cbor-tags")
31
+ @assigneds = []
32
+ @unassigneds = []
33
+ REXML::XPath.each(doc.root,
34
+ "//xmlns:registry[@id='tags']/xmlns:record",
35
+ IANA::Registry::NS) do |x|
36
+ value = x.elements['value']
37
+ s, e = value.text.split("-").map {Integer(_1)}
38
+ semantics = x.elements['semantics']
39
+ if semantics.text
40
+ @assigneds << [s, e || s, semantics.text]
41
+ else
42
+ @unassigneds << [s, e || s]
43
+ end
44
+ end.compact
45
+ warn "** IANA cbor-tags inconstency" if @assigneds.sort != @assigneds
46
+ end
47
+
48
+ def find(n, intv = assigneds)
49
+ idx = intv.bsearch_index { |s, e| e >= n }
50
+ if idx && intv[idx][0] <= n
51
+ [n, intv[idx]]
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,22 @@
1
+ require 'iana-registry'
2
+
3
+
4
+ #if ENV["TAG_REPORT_TEST"]
5
+
6
+ require_relative "../bin/cbor-tag-report.rb"
7
+
8
+ reg = IANA::Registry::CBOR_TAGS.new
9
+
10
+ testcases = 20.times.map do
11
+ (2 ** (Random.rand(Float(4)))**3).floor - 1
12
+ end + [0, 2, 109, 120, 121, 125, 127, 128,
13
+ 18299, 18300, 18555, 18556, 18557, 18810, 18811, 18812]
14
+
15
+ o = testcases.sort.uniq.map do |n|
16
+ [reg.find(n), reg.find(n, reg.unassigneds)]
17
+ end
18
+
19
+ require 'pp'
20
+ pp o
21
+ #end
22
+
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iana-registry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Carsten Bormann
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: This gem provides generalized access to XML-based IANA registries.
13
+ email: cabo@tzi.org
14
+ executables:
15
+ - cbor-tag-report.rb
16
+ - dns-parameters.rb
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/cbor-tag-report.rb
21
+ - bin/dns-parameters.rb
22
+ - iana-registry.gemspec
23
+ - lib/iana-registry.rb
24
+ - test/test-iana-registry.rb
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '2.7'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 4.0.2
43
+ specification_version: 4
44
+ summary: provides generalized access to IANA registries.
45
+ test_files:
46
+ - test/test-iana-registry.rb