dnsruby 1.42 → 1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,10 @@ module Dnsruby
46
46
  def from_data(data) #:nodoc: all
47
47
  @order, @preference, @flags, @service, @regexp, @replacement = data
48
48
  end
49
+
50
+ def regexp=(s)
51
+ @regexp = TXT.parse(s)[0]
52
+ end
49
53
 
50
54
  def from_string(input) #:nodoc: all
51
55
  if (input.length > 0)
@@ -54,9 +58,7 @@ module Dnsruby
54
58
  @preference = values [1].to_i
55
59
  @flags = values [2].gsub!("\"", "")
56
60
  @service = values [3].gsub!("\"", "")
57
- re = values [4].gsub!("\"", "")
58
- re.gsub!("\\\\", "\\")
59
- @regexp = re
61
+ @regexp = TXT.parse(values[4])[0]
60
62
  @replacement = Name.create(values[5])
61
63
  end
62
64
  end
@@ -64,15 +66,9 @@ module Dnsruby
64
66
  def rdata_to_string #:nodoc: all
65
67
  if (@order!=nil)
66
68
  ret = "#{@order} #{@preference} \"#{@flags}\" \"#{@service}\" \""
67
- ##{@regexp}
68
- @regexp.each_byte {|b|
69
- c = b.chr
70
- if (c == "\\")
71
- ret += "\\"
72
- end
73
- ret += c
74
- }
69
+ ret += TXT.display(@regexp)
75
70
  ret += "\" #{@replacement}"
71
+
76
72
  return ret
77
73
  else
78
74
  return ""
@@ -142,6 +142,12 @@ module Dnsruby
142
142
 
143
143
  def calculate_mac(algorithm, data)
144
144
  mac=nil
145
+ #+ if (key_size > max_digest_len) {
146
+ #+ EVP_DigestInit(&ectx, digester);
147
+ #+ EVP_DigestUpdate(&ectx, (const void*) key_bytes, key_size);
148
+ #+ EVP_DigestFinal(&ectx, key_bytes, NULL);
149
+ #+ key_size = max_digest_len;
150
+ #+ }
145
151
  key = @key.gsub(" ", "")
146
152
  # key = Base64::decode64(key)
147
153
  key = key.unpack("m*")[0]
@@ -14,7 +14,7 @@
14
14
  #limitations under the License.
15
15
  #++
16
16
  begin
17
- require 'jcode'
17
+ require 'jcode'
18
18
  rescue LoadError => e
19
19
  end
20
20
  module Dnsruby
@@ -46,6 +46,10 @@ module Dnsruby
46
46
  ESCAPE_CODES = ESCAPE_CHARS.invert
47
47
 
48
48
  def from_string(input)
49
+ @strings = TXT.parse(input)
50
+ end
51
+
52
+ def TXT.parse(input)
49
53
  # Need to look out for special characters.
50
54
  # Need to split the input up into strings (which are defined by non-escaped " characters)
51
55
  # Then need to fix up any \ escape characters (should just be " and ; and binary?)
@@ -112,8 +116,10 @@ module Dnsruby
112
116
  strings[count]+=c
113
117
  else
114
118
  # Must be building up three digit string to identify binary value?
115
- current_binary += c
116
- if (current_binary.length == 3)
119
+ # if (c >= "0" && c <= "9")
120
+ current_binary += c
121
+ # end
122
+ if ((current_binary.length == 3) ) # || (c < "0" || c > "9"))
117
123
  strings[count]+=current_binary.to_i.chr
118
124
  in_escaped = false
119
125
  current_binary = ""
@@ -126,39 +132,45 @@ module Dnsruby
126
132
  end
127
133
  pos += 1
128
134
  }
129
- @strings=strings
135
+ return strings
136
+ end
137
+
138
+ def TXT.display(str, do_escapes = true)
139
+ output = ""
140
+ # Probably need to scan through each string manually
141
+ # Make sure to remember to escape binary characters.
142
+ # Go through copying to output, and adding "\" characters as necessary?
143
+ str.each_byte {|c|
144
+ if (c == 34) || (c == 92) # || (c == 59)
145
+ if (do_escapes)
146
+ output+='\\'
147
+ end
148
+ output+=c.chr
149
+ elsif (c < 32) # c is binary
150
+ if (ESCAPE_CODES[c])
151
+ output += c.chr
152
+ else
153
+ output+= '\\'
154
+ num = c.to_i.to_s
155
+ (3-num.length).times {|i|
156
+ num="0"+num
157
+ }
158
+ output+= num # Need a 3 digit number here.
159
+ end
160
+
161
+ else
162
+ output += c.chr
163
+ end
164
+ }
165
+ return output
130
166
  end
131
167
 
132
168
  def rdata_to_string
133
169
  if (defined?@strings)
134
170
  temp = []
135
171
  @strings.each {|str|
136
- output = "\""
137
- # Probably need to scan through each string manually
138
- # Make sure to remember to escape binary characters.
139
- # Go through copying to output, and adding "\" characters as necessary?
140
- str.each_byte {|c|
141
- if (c == 34) || (c == 92) # || (c == 59)
142
- output+='\\'
143
- output+=c.chr
144
- elsif (c < 32) # c is binary
145
- if (ESCAPE_CODES[c])
146
- output += c.chr
147
- else
148
- output+= '\\'
149
- num = c.to_i.to_s
150
- (3-num.length).times {|i|
151
- num="0"+num
152
- }
153
- output+= num # Need a 3 digit number here.
154
- end
155
-
156
- else
157
- output += c.chr
158
- end
159
- }
160
- output+="\""
161
- temp.push(output)
172
+ output = TXT.display(str)
173
+ temp.push("\"#{output}\"")
162
174
  }
163
175
  return temp.join(' ')
164
176
  end
@@ -161,6 +161,9 @@ module Dnsruby
161
161
  end
162
162
  else
163
163
  if (escaped)
164
+ if (c >= "0" && c <= "9") # rfc 1035 5.1 \DDD
165
+ pos = pos + 2
166
+ end
164
167
  escaped = false
165
168
  next
166
169
  else
@@ -215,11 +218,19 @@ module Dnsruby
215
218
  name = split[0].strip
216
219
  if (name.index"\\")
217
220
  old_name = name
218
- name = Name.create(name).to_s
221
+
222
+ ls =[]
223
+ Name.create(name).labels.each {|el| ls.push(Name.decode(RR::TXT.display(el.to_s, false)))}
224
+ name = ls.join('.')
225
+
226
+
219
227
  if (/\.\z/ =~ old_name)
220
228
  name += "."
221
229
  end
222
- line.sub!(old_name, name)
230
+ line = name + " "
231
+ (split.length - 1).times {|i| line += "#{split[i+1]} "}
232
+ line += "\n"
233
+ split = line.split
223
234
  end
224
235
  # o add $ORIGIN to it if it is not absolute
225
236
  if !(/\.\z/ =~ name)
data/lib/dnsruby.rb CHANGED
@@ -104,7 +104,7 @@ require 'Dnsruby/TheLog'
104
104
  module Dnsruby
105
105
 
106
106
  # @TODO@ Remember to update version in dnsruby.gemspec!
107
- VERSION = 1.42
107
+ VERSION = 1.43
108
108
  def Dnsruby.version
109
109
  return VERSION
110
110
  end
data/test/tc_naptr.rb CHANGED
@@ -46,9 +46,15 @@ class TestNAPTR < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  def test_string
49
- txt = 'all.rr.org. 7200 IN NAPTR 100 10 "" "" "/urn:cid:.+@([^\\.]+\\.)(.*)$/\\2/i" .'
49
+ txt = 'all.rr.org. 7200 IN NAPTR 100 10 "" "" "/urn:cid:.+@([^\\\\.]+\\\\.)(.*)$/\\\\2/i" .'
50
50
  rr = RR.create(txt)
51
51
  assert(rr.to_s.index('"/urn:cid:.+@([^\\\\.]+\\\\.)(.*)$/\\\\2/i"'), '"/urn:cid:.+@([^\\\\.]+\\\\.)(.*)$/\\\\2/i"' + "\n" + rr.to_s)
52
52
  end
53
53
 
54
+ def test_bad_string
55
+ txt = 'all.rr.binary.org. IN NAPTR 100 10 "" "" "/urn:cid:.+@([^\\.]+\\.)(.*)$/\\\\2/i" .'
56
+ rr = RR.create(txt)
57
+ assert(rr.to_s.index('"/urn:cid:.+@([^.]+.)(.*)$/\\\\2/i"'), '"/urn:cid:.+@([^.]+.)(.*)$/\\\\2/i"' + "\n" + rr.to_s)
58
+ end
59
+
54
60
  end
data/test/tc_rr.rb CHANGED
@@ -259,7 +259,7 @@ class TestRR < Test::Unit::TestCase
259
259
  end
260
260
  end
261
261
  end
262
-
262
+
263
263
  rr2 = RR.new_from_string(rr.to_s)
264
264
  assert_equal(rr.to_s, rr2.to_s, "#{type} - Parsing from string works")
265
265
  end
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.42"
4
+ version: "1.43"
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: 2010-01-08 00:00:00 +00:00
12
+ date: 2010-02-02 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15