Class: Dnsruby::RR::CERT

Inherits:
Dnsruby::RR show all
Defined in:
lib/dnsruby/resource/CERT.rb

Overview

Class for DNS Certificate (CERT) resource records. (see RFC 2538)

RFC 2782

Defined Under Namespace

Classes: CertificateTypes

Constant Summary collapse

ClassValue =

:nodoc: all

nil
TypeValue =

:nodoc: all

Types::CERT

Constants inherited from Dnsruby::RR

ClassInsensitiveTypes

Instance Attribute Summary collapse

Attributes inherited from Dnsruby::RR

#klass, #name, #rdata, #ttl, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dnsruby::RR

#<=>, #==, #clone, create, #eql?, find_class, get_class, get_num, #hash, implemented_rrs, #init_defaults, new_from_data, new_from_hash, new_from_string, #rdlength, #sameRRset, #to_s

Instance Attribute Details

#algObject

Returns the algorithm used by the certificate



30
31
32
# File 'lib/dnsruby/resource/CERT.rb', line 30

def alg
  @alg
end

#certObject

Returns the data comprising the certificate itself (in raw binary form)



32
33
34
# File 'lib/dnsruby/resource/CERT.rb', line 32

def cert
  @cert
end

#certtypeObject

Returns the format code for the certificate



26
27
28
# File 'lib/dnsruby/resource/CERT.rb', line 26

def certtype
  @certtype
end

#keytagObject

Returns the key tag for the public key in the certificate



28
29
30
# File 'lib/dnsruby/resource/CERT.rb', line 28

def keytag
  @keytag
end

Class Method Details

.decode_rdata(msg) ⇒ Object

:nodoc: all



98
99
100
101
102
# File 'lib/dnsruby/resource/CERT.rb', line 98

def self.decode_rdata(msg) #:nodoc: all
  certtype, keytag, alg = msg.get_unpack('nnc')
  cert = msg.get_bytes
  return self.new([certtype, keytag, alg, cert])
end

Instance Method Details

#encode_rdata(msg, canonical = false) ⇒ Object

:nodoc: all



93
94
95
96
# File 'lib/dnsruby/resource/CERT.rb', line 93

def encode_rdata(msg, canonical=false) #:nodoc: all
  msg.put_pack('nnc', @certtype.code, @keytag, @alg.code)
  msg.put_bytes(@cert)
end

#from_data(data) ⇒ Object

:nodoc: all



49
50
51
52
53
54
# File 'lib/dnsruby/resource/CERT.rb', line 49

def from_data(data) #:nodoc: all
  @certtype = CertificateTypes::new(data[0])
  @keytag = data[1]
  @alg = Dnsruby::Algorithms.new(data[2])
  @cert= data[3]
end

#from_hash(hash) ⇒ Object

:nodoc: all



56
57
58
59
60
61
# File 'lib/dnsruby/resource/CERT.rb', line 56

def from_hash(hash) #:nodoc: all
  @certtype = CertificateTypes::new(hash[:certtype])
  @keytag = hash[:keytag]
  @alg = Dnsruby::Algorithms.new(hash[:alg])
  @cert= hash[:cert]
end

#from_string(input) ⇒ Object

:nodoc: all



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/dnsruby/resource/CERT.rb', line 63

def from_string(input) #:nodoc: all
  if (input != "")
    names = input.split(" ")
    begin
      @certtype = CertificateTypes::new(names[0])
    rescue ArgumentError
      @certtype = CertificateTypes::new(names[0].to_i)
    end
    @keytag = names[1].to_i
    begin
      @alg = Dnsruby::Algorithms.new(names[2])
    rescue ArgumentError
      @alg = Dnsruby::Algorithms.new(names[2].to_i)
    end
    buf = ""
    (names.length - 3).times {|index|
      buf += names[index + 3]
    }


    buf.gsub!(/\n/, "")
    buf.gsub!(/ /, "")
    @cert = buf.unpack("m*").first
  end
end

#rdata_to_stringObject

:nodoc: all



89
90
91
# File 'lib/dnsruby/resource/CERT.rb', line 89

def rdata_to_string #:nodoc: all
  return "#{@certtype.string} #{@keytag} #{@alg.string} #{[@cert.to_s].pack("m*").gsub("\n", "")}"
end