Sha256: bc7090132d5d9bcf338e42a527b730c7daff29f2e2313ad092a8a4ce54c996df

Contents?: true

Size: 1 KB

Versions: 8

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

# Ruby internal
require 'csv'

# TLS map module
module TLSmap
  # TLS mapping
  class App
    IANA_URL = 'https://www.iana.org/assignments/tls-parameters/tls-parameters-4.csv'

    # remove Reserved, Unassigned codepoints (those with a range: X-X or *)
    # also works with gnutls
    def codepoint_iana(raw_cp)
      c1, c2 = raw_cp.split(',')
      c2.strip!
      return nil unless c2.size == 4

      "#{c1[2..3]}#{c2[2..3]}"
    end

    # remove remaining Reserved, Unassigned codepoints
    def desc_iana(desc)
      return nil if /Reserved|Unassigned/.match?(desc)

      desc
    end

    def parse_iana
      CSV.foreach(@iana_file.path, **{ headers: true, header_converters: :symbol }) do |alg|
        codepoint = codepoint_iana(alg[:value])
        description = desc_iana(alg[:description])
        @tls_map << { codepoint: codepoint, iana: description } unless codepoint.nil? || description.nil?
      end
    end

    private :codepoint_iana, :desc_iana, :parse_iana
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tls-map-2.1.0 lib/tls_map/app/iana.rb
tls-map-2.0.0 lib/tls_map/app/iana.rb
tls-map-1.3.2 lib/tls_map/iana.rb
tls-map-1.3.1 lib/tls_map/iana.rb
tls-map-1.3.0 lib/tls_map/iana.rb
tls-map-1.2.0 lib/tls_map/iana.rb
tls-map-1.1.0 lib/tls_map/iana.rb
tls-map-1.0.0 lib/tls_map/iana.rb