dnsruby 1.31 → 1.32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Dnsruby/name.rb CHANGED
@@ -55,7 +55,7 @@ module Dnsruby
55
55
  return Name.new(split_escaped(arg), /\.\z/ =~ arg ? true : false)
56
56
  # return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
57
57
  when Array
58
- return Name.new(arg, /\.\z/ =~ ((arg.last.kind_of?String)?arg.last : arg.last.string) ? true : false)
58
+ return Name.new(arg, /\.\z/ =~ (arg.last ? ((arg.last.kind_of?String)?arg.last : arg.last.string) : arg.last) ? true : false)
59
59
  else
60
60
  raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
61
61
  end
@@ -209,7 +209,13 @@ module Dnsruby
209
209
  index = 4
210
210
  end
211
211
  (index..end_index).each {|i|
212
- buf += data[i]
212
+ if (comment_index = data[i].index(";"))
213
+ buf += data[i].slice(0, comment_index)
214
+ # @TODO@ We lose the comments here - we should really keep them for when we write back to string format?
215
+ break
216
+ else
217
+ buf += data[i]
218
+ end
213
219
  }
214
220
  # self.digest=Base64.decode64(buf)
215
221
  buf.gsub!(/\n/, "")
@@ -206,7 +206,8 @@ module Dnsruby
206
206
  self.flags=(flags)
207
207
  self.iterations=(iterations)
208
208
  # self.salt_length=(salt_length)
209
- self.salt=(salt)
209
+ # self.salt=(salt)
210
+ @salt=salt
210
211
  self.hash_length=(hash_length)
211
212
  self.next_hashed=(next_hashed)
212
213
  self.types=(types)
@@ -299,7 +300,8 @@ module Dnsruby
299
300
  end
300
301
 
301
302
  def encode_rdata(msg, canonical=false) #:nodoc: all
302
- s = salt()
303
+ # s = salt()
304
+ s = @salt
303
305
  sl = s.length()
304
306
  if (s == "-")
305
307
  sl = 0
@@ -90,7 +90,8 @@ module Dnsruby
90
90
  self.flags=(flags)
91
91
  self.iterations=(iterations)
92
92
  # self.salt_length=(salt_length)
93
- self.salt=(salt)
93
+ # self.salt=(salt)
94
+ @salt=salt
94
95
  end
95
96
 
96
97
  def from_string(input)
@@ -110,7 +111,8 @@ module Dnsruby
110
111
  end
111
112
 
112
113
  def encode_rdata(msg, canonical=false) #:nodoc: all
113
- s = salt()
114
+ # s = salt()
115
+ s = @salt
114
116
  sl = s.length()
115
117
  if (s == "-")
116
118
  sl == 0
@@ -202,7 +202,7 @@ module Dnsruby
202
202
  # digits, while the decimal representation of a 32-bit unsigned integer
203
203
  # can never be longer than 10 digits.
204
204
  if (input.length == 10)
205
- return input
205
+ return input.to_i
206
206
  elsif (input.length == 14)
207
207
  year = input[0,4]
208
208
  mon=input[4,2]
@@ -210,20 +210,20 @@ module Dnsruby
210
210
  hour=input[8,2]
211
211
  min=input[10,2]
212
212
  sec=input[12,2]
213
- return Time.mktime(year, mon, day, hour, min, sec).to_i
213
+ return Time.gm(year, mon, day, hour, min, sec).to_i
214
214
  else
215
215
  raise DecodeError.new("RRSIG : Illegal time value #{input} - see RFC 4034 section 3.2")
216
216
  end
217
217
  end
218
218
 
219
219
  def format_time(time)
220
- return Time.at(time).strftime("%Y%m%d%H%M%S")
220
+ return Time.at(time).gmtime.strftime("%Y%m%d%H%M%S")
221
221
  end
222
222
 
223
223
  def rdata_to_string #:nodoc: all
224
224
  if (@type_covered!=nil)
225
225
  # signature = Base64.encode64(@signature) # .gsub(/\n/, "")
226
- signature = [@signature].pack("m*") # .gsub(/\n/, "")
226
+ signature = [@signature].pack("m*").gsub(/\n/, "")
227
227
  # @TODO@ Display the expiration and inception as
228
228
  return "#{@type_covered.string} #{@algorithm.string} #{@labels} #{@original_ttl} " +
229
229
  "#{format_time(@expiration)} ( #{format_time(@inception)} " +
@@ -259,7 +259,7 @@ module Dnsruby
259
259
  #the Signature field excluded;
260
260
  data = MessageEncoder.new { |msg|
261
261
  msg.put_pack('ncc', @type_covered.to_i, @algorithm.to_i, @labels)
262
- msg.put_pack("NNN", @original_ttl, @expiration.to_i, @inception.to_i)
262
+ msg.put_pack("NNN", @original_ttl, @expiration, @inception)
263
263
  msg.put_pack("n", @key_tag)
264
264
  msg.put_name(@signers_name, true)
265
265
  }.to_s
@@ -114,7 +114,7 @@ module Dnsruby
114
114
  # Check that the RRSet and RRSIG record are compatible
115
115
  def check_rr_data(rrset, sigrec)#:nodoc: all
116
116
  #Each RR MUST have the same owner name as the RRSIG RR;
117
- if (rrset.name.to_s.downcase != sigrec.name.to_s.downcase)
117
+ if (rrset.name.canonical != sigrec.name.canonical)
118
118
  raise VerifyError.new("RRSET should have same owner name as RRSIG for verification (rrsert=#{rrset.name}, sigrec=#{sigrec.name}")
119
119
  end
120
120
 
@@ -280,7 +280,7 @@ module Dnsruby
280
280
  # if (all_delegate && rrset.sigs.length == 0)
281
281
  # next
282
282
  # end
283
- if ((rrset.name.to_s.downcase == msg.question()[0].qname.to_s.downcase) && (rrset.sigs.length == 0))
283
+ if ((rrset.name.canonical == msg.question()[0].qname.canonical) && (rrset.sigs.length == 0))
284
284
  next
285
285
  end
286
286
  end
@@ -866,11 +866,12 @@ module Dnsruby
866
866
  # If we get to root, then return false
867
867
  n = Name.create(name)
868
868
  root = Name.create(".")
869
- while (n != root)
869
+ while (true) # n != root)
870
870
  # Try the trusted keys first, then the DS set
871
871
  (@trust_anchors.keys + @trusted_keys.keys + @configured_ds_store + @discovered_ds_store).each {|key|
872
- return key if key.name.to_s.downcase == n.to_s.downcase
872
+ return key if key.name.canonical == n.canonical
873
873
  }
874
+ break if (n == root)
874
875
  # strip the name
875
876
  n = n.strip_label
876
877
  end
@@ -1095,7 +1096,7 @@ module Dnsruby
1095
1096
  if (!ns_rrset || ns_rrset.length == 0)
1096
1097
  ns_rrset = ns_ret.authority.rrset(name, Types.NS) # @TOO@ Is ths OK?
1097
1098
  end
1098
- if (!ns_rrset || ns_rrset.length == 0 || ns_rrset.name.to_s != name.to_s)
1099
+ if (!ns_rrset || ns_rrset.length == 0 || ns_rrset.name.canonical != name.canonical)
1099
1100
  return nil
1100
1101
  end
1101
1102
  if (ns_rrset.sigs.length > 0)
@@ -1132,7 +1133,7 @@ module Dnsruby
1132
1133
  # and see if we can find any of the names in the A/AAAA records in ns_additional
1133
1134
  found_addr = false
1134
1135
  ns_additional.each {|addr_rr|
1135
- if (ns_rr.nsdname.to_s == addr_rr.name.to_s)
1136
+ if (ns_rr.nsdname.canonical == addr_rr.name.canonical)
1136
1137
  # print "Found address #{addr_rr.address} for #{ns_rr.nsdname}\n"
1137
1138
  nameservers.push(addr_rr.address.to_s)
1138
1139
  found_addr = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.31"
4
+ version: "1.32"
5
5
  platform: ruby
6
6
  authors:
7
7
  - AlexD
@@ -9,7 +9,7 @@ autorequire: dnsruby
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-04 00:00:00 +01:00
12
+ date: 2009-06-09 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15