Class: Net::DNS::RR::CERT

Inherits:
Net::DNS::RR show all
Defined in:
lib/Net/DNS/RR/CERT.rb

Overview

RFC 2782

Constant Summary collapse

FORMATS =
{
'PKIX' => 1,
'SPKI' => 2,
'PGP'  => 3,
'URI'  => 253,
'OID'  => 254,
}
R_FORMATS =
FORMATS.invert
ALGORITHMS =
{
'RSAMD5'     => 1,
'DH'         => 2,
'DSA'        => 3,
'ECC'        => 4,
'INDIRECT'   => 252,
'PRIVATEDNS' => 253,
'PRIVATEOID' => 254,
}
R_ALGORITHMS =
ALGORITHMS.invert

Constants inherited from Net::DNS::RR

RRS

Instance Attribute Summary collapse

Attributes inherited from Net::DNS::RR

#name, #rdata, #rdlength, #rrclass, #ttl, #type

Instance Method Summary collapse

Methods inherited from Net::DNS::RR

#_canonicalRdata, #_canonicaldata, _get_subclass, _name2wire, #_name2wire, build_regex, create, #create_rrsort_func, #data, #get_rrsort_func, #init, #init_rrsort_func, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func

Instance Attribute Details

#algorithmObject

print “algorithm = ”, rr.algorithm, “n”



59
60
61
# File 'lib/Net/DNS/RR/CERT.rb', line 59

def algorithm
  @algorithm
end

#certificateObject

print “certificate = ”, rr.certificate, “n”



64
65
66
# File 'lib/Net/DNS/RR/CERT.rb', line 64

def certificate
  @certificate
end

#formatObject

print “format = ”, rr.format, “n”



49
50
51
# File 'lib/Net/DNS/RR/CERT.rb', line 49

def format
  @format
end

#tagObject

print “tag = ”, rr.tag, “n”



54
55
56
# File 'lib/Net/DNS/RR/CERT.rb', line 54

def tag
  @tag
end

Instance Method Details

#new_from_data(data, offset) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/Net/DNS/RR/CERT.rb', line 87

def new_from_data(data, offset)
  if (@rdlength > 0)
    format, tag, algorithm = data.unpack("\@#{offset} n2C");
    
    offset        += 2 * Net::DNS::INT16SZ + 1;
    
    length      = @rdlength - (2 * Net::DNS::INT16SZ + 1);
    certificate = data[offset, length];
    
    @format      = format;
    @tag         = tag;
    @algorithm   = algorithm;
    @certificate = certificate;
  end
end

#new_from_hash(values) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/Net/DNS/RR/CERT.rb', line 103

def new_from_hash(values)
  if values.has_key?(:format)
    @format = values[:format]
  end
  if values.has_key?(:tag)
    @tag = values[:tag]
  end
  if values.has_key?(:algorithm)
    @algorithm = values[:algorithm]
  end
  if values.has_key?(:certificate)
    @certificate = values[:certificate]
  end
end

#new_from_string(string) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/Net/DNS/RR/CERT.rb', line 118

def new_from_string(string)
  if (string==nil)
    return
  end
  
  format, tag, algorithm, rest = string.split(" ")
  if (rest == nil) 
    return
  end
  
  # look up mnemonics
  # the "die"s may be rash, but proceeding would be dangerous
  if (algorithm =~ /\D/)
    if defined?ALGORITHMS[algorithm]
      algorithm = ALGORITHMS[algorithm]
    else
      raise RuntimeError,	"Unknown algorithm mnemonic: '#{algorithm}'"
    end
  end
  
  if (format =~ /\D/)
    if defined?FORMATS[format]
      format = FORMATS[format]
    else
      die "Unknown format mnemonic: '#{format}'"
    end
  end
  
  @format      = format;
  @tag        = tag;
  @algorithm   = algorithm;
  @certificate = Base64::decode64([rest].join(''));
end

#rdatastrObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/Net/DNS/RR/CERT.rb', line 152

def rdatastr
  rdatastr=""
  
  if (defined?@format)
    cert = Base64::encode64 @certificate;
    cert.gsub!(/\n/,"");
    
    format = @format
    if defined?R_FORMATS[@format] 
      format = R_FORMATS[@format]
    end
    
    algorithm = @algorithm;
    if  defined?R_ALGORITHMS[@algorithm]  
      algorithm = R_ALGORITHMS[@algorithm] 
    end
    
    rdatastr = "#{format} #{@tag} #{algorithm} #{cert}";
  else
    rdatastr = '';
  end
  
  return rdatastr;
end

#rr_rdata(packet, offset) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/Net/DNS/RR/CERT.rb', line 177

def rr_rdata(packet, offset)
  rdata = "";
  
  if (defined?@format)
    rdata += [@format, @tag].pack("n2")
    rdata += [@algorithm].pack("C")
    rdata += @certificate
  end
  
  return rdata;
end