Sha256: 5b22f88131e9b8133228e3d21a0e648c29d2333d44cdc3dcb8957075bffe7947

Contents?: true

Size: 1.26 KB

Versions: 39

Compression:

Stored size: 1.26 KB

Contents

module RecordStore
  class Record::SSHFP < Record
    attr_accessor :algorithm, :fptype, :fingerprint

    # https://www.iana.org/assignments/dns-sshfp-rr-parameters/dns-sshfp-rr-parameters.xhtml
    module Algorithms
      RESERVED = 0
      RSA = 1
      DSA = 2
      ECDSA = 3
      ED25519 = 4
      UNASSIGNED = 5
      ED448 = 6
    end

    module FingerprintTypes
      RESERVED = 0
      SHA_1 = 1
      SHA_256 = 2
    end

    FINGERPRINT_REGEX = /\A[[:xdigit:]]+\z/

    class << self
      private

      def constants_defined_in(mod)
        mod.constants(false).map(&mod.method(:const_get))
      end
    end

    validates :algorithm, presence: true, inclusion: { in: constants_defined_in(Algorithms) }
    validates :fingerprint, presence: true, format: { with: FINGERPRINT_REGEX }
    validates :fptype, presence: true, inclusion: { in: constants_defined_in(FingerprintTypes) }

    def initialize(record)
      super

      @algorithm = record.fetch(:algorithm)
      @fptype = record.fetch(:fptype)
      @fingerprint = record.fetch(:fingerprint)
    end

    def rdata
      {
        algorithm: algorithm,
        fingerprint: fingerprint,
        fptype: fptype,
      }
    end

    def rdata_txt
      "#{algorithm} #{fptype} #{fingerprint}"
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
record_store-8.0.5 lib/record_store/record/sshfp.rb
record_store-8.0.4 lib/record_store/record/sshfp.rb
record_store-8.0.3 lib/record_store/record/sshfp.rb
record_store-8.0.2 lib/record_store/record/sshfp.rb
record_store-8.0.1 lib/record_store/record/sshfp.rb
record_store-8.0.0 lib/record_store/record/sshfp.rb
record_store-7.1.1 lib/record_store/record/sshfp.rb
record_store-7.1.0 lib/record_store/record/sshfp.rb
record_store-7.0.1 lib/record_store/record/sshfp.rb
record_store-7.0.0 lib/record_store/record/sshfp.rb
record_store-6.7.2 lib/record_store/record/sshfp.rb
record_store-6.7.1 lib/record_store/record/sshfp.rb
record_store-6.7.0 lib/record_store/record/sshfp.rb
record_store-6.6.0 lib/record_store/record/sshfp.rb
record_store-6.5.11 lib/record_store/record/sshfp.rb
record_store-6.5.10 lib/record_store/record/sshfp.rb
record_store-6.5.9 lib/record_store/record/sshfp.rb
record_store-6.5.8 lib/record_store/record/sshfp.rb
record_store-6.5.5 lib/record_store/record/sshfp.rb
record_store-6.5.4 lib/record_store/record/sshfp.rb