dnsruby 1.39 → 1.40

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.
@@ -384,7 +384,7 @@ module Dnsruby
384
384
 
385
385
  # Make sure that known_authorities still contains some authorities!
386
386
  # If not, remove the zone from zones_cache, and start again
387
- if (known_authorities.values.length > 0)
387
+ if (known_authorities && known_authorities.values.length > 0)
388
388
  done = true
389
389
  else
390
390
  @@mutex.synchronize{
@@ -103,7 +103,7 @@ module Dnsruby
103
103
  code = array.stringsdown[arg.downcase]
104
104
  if (code != nil)
105
105
  @code = code
106
- @string = array.strings.invert[@code]
106
+ @string = array.values[@code]
107
107
  else
108
108
  unknown_string(arg)
109
109
  end
@@ -125,7 +125,7 @@ module Dnsruby
125
125
  def set_string(arg)
126
126
  array = @@arrays[self.class]
127
127
  @code = array.stringsdown[arg.downcase]
128
- @string = array.strings.invert[@code]
128
+ @string = array.values[@code]
129
129
  end
130
130
 
131
131
  def set_code(arg)
@@ -162,18 +162,9 @@ module Dnsruby
162
162
  end
163
163
 
164
164
  def ==(other)
165
- if Fixnum === other
166
- if other == @code
167
- return true
168
- end
169
- elsif String === other
170
- if other == @string
171
- return true
172
- end
173
- elsif CodeMapper === other
174
- if other.string == @string && other.code == @code
175
- return true
176
- end
165
+ return true if [@code, @string].include?other
166
+ if (CodeMapper === other)
167
+ return true if ((other.code == @code) || (other.string == @string))
177
168
  end
178
169
  return false
179
170
  end
@@ -72,7 +72,7 @@ module Dnsruby
72
72
  return labels
73
73
  end
74
74
 
75
- attr_reader :labels
75
+ attr_accessor :labels
76
76
 
77
77
  #This method should only be called internally.
78
78
  #Use Name::create to create a new Name
@@ -172,7 +172,7 @@ module Dnsruby
172
172
  end
173
173
 
174
174
  def ==(other) # :nodoc:
175
- return false unless Name === other
175
+ return false if other.class != Name
176
176
  return @labels == other.labels && @absolute == other.absolute?
177
177
  end
178
178
  alias eql? == # :nodoc:
@@ -267,9 +267,10 @@ module Dnsruby
267
267
  # I start looking forward and do the magic.
268
268
 
269
269
  i=0;
270
-
270
+
271
+ unpacked = wire.unpack("C*")
271
272
  while (i < length )
272
- c=wire.unpack("x#{i}C1") [0]
273
+ c = unpacked[i]
273
274
  if ( c < 33 || c > 126 )
274
275
  presentation=presentation + sprintf("\\%03u" ,c)
275
276
  elsif ( c.chr == "\"" )
@@ -378,6 +379,7 @@ module Dnsruby
378
379
  end
379
380
  @downcase = string.downcase
380
381
  @string = string
382
+ @string_length = string.length
381
383
  end
382
384
  attr_reader :string, :downcase
383
385
 
@@ -386,7 +388,7 @@ module Dnsruby
386
388
  end
387
389
 
388
390
  def length
389
- return @string.length
391
+ return @string_length
390
392
  end
391
393
 
392
394
  def inspect
@@ -53,7 +53,7 @@ module Dnsruby
53
53
  end
54
54
 
55
55
  def encode_rdata(msg, canonical=false) #:nodoc: all
56
- msg.put_pack("n", @subtype)
56
+ msg.put_pack("n", @subtype.to_i)
57
57
  msg.put_name(@hostname, canonical)
58
58
  end
59
59
 
@@ -63,25 +63,38 @@ module Dnsruby
63
63
  def from_string(input) #:nodoc: all
64
64
  if (input != "")
65
65
  names = input.split(" ")
66
- @certtype = CertificateTypes::new(names[0])
66
+ begin
67
+ @certtype = CertificateTypes::new(names[0])
68
+ rescue ArgumentError
69
+ @certtype = CertificateTypes::new(names[0].to_i)
70
+ end
67
71
  @keytag = names[1].to_i
68
- @alg = Dnsruby::Algorithms.new(names[2])
69
- @cert = names[3]
72
+ begin
73
+ @alg = Dnsruby::Algorithms.new(names[2])
74
+ rescue ArgumentError
75
+ @alg = Dnsruby::Algorithms.new(names[2].to_i)
76
+ end
77
+ buf = names[3]
78
+
79
+
80
+ buf.gsub!(/\n/, "")
81
+ buf.gsub!(/ /, "")
82
+ @cert = buf.unpack("m*").first
70
83
  end
71
84
  end
72
85
 
73
86
  def rdata_to_string #:nodoc: all
74
- return "#{@certtype.string} #{@keytag} #{@alg.string} #{@cert}"
87
+ return "#{@certtype.string} #{@keytag} #{@alg.string} #{[@cert.to_s].pack("m*").gsub("\n", "")}"
75
88
  end
76
89
 
77
90
  def encode_rdata(msg, canonical=false) #:nodoc: all
78
- msg.put_pack('nnn', @certtype.code, @keytag, @alg.code)
79
- msg.put_string(@cert)
91
+ msg.put_pack('nnc', @certtype.code, @keytag, @alg.code)
92
+ msg.put_bytes(@cert)
80
93
  end
81
94
 
82
95
  def self.decode_rdata(msg) #:nodoc: all
83
- certtype, keytag, alg = msg.get_unpack('nnn')
84
- cert = msg.get_string
96
+ certtype, keytag, alg = msg.get_unpack('nnc')
97
+ cert = msg.get_bytes
85
98
  return self.new([certtype, keytag, alg, cert])
86
99
  end
87
100
  end
@@ -0,0 +1,55 @@
1
+ #--
2
+ #Copyright 2007 Nominet UK
3
+ #
4
+ #Licensed under the Apache License, Version 2.0 (the "License");
5
+ #you may not use this file except in compliance with the License.
6
+ #You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ #Unless required by applicable law or agreed to in writing, software
11
+ #distributed under the License is distributed on an "AS IS" BASIS,
12
+ #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ #See the License for the specific language governing permissions and
14
+ #limitations under the License.
15
+ #++
16
+ module Dnsruby
17
+ class RR
18
+ #Class for DNS DHCP ID (DHCID) resource records.
19
+ #RFC 4701
20
+ class DHCID < RR
21
+ ClassValue = nil #:nodoc: all
22
+ TypeValue= Types::DHCID #:nodoc: all
23
+
24
+ #The opaque rdata for DHCID
25
+ attr_accessor :dhcid_data
26
+
27
+ def from_hash(hash) #:nodoc: all
28
+ @dhcid_data = hash[:dhcid_data]
29
+ end
30
+
31
+ def from_data(data) #:nodoc: all
32
+ @dhcid_data, = data
33
+ end
34
+
35
+ def from_string(input) #:nodoc: all
36
+ buf = input.gsub(/\n/, "")
37
+ buf.gsub!(/ /, "")
38
+ @dhcid_data = buf.unpack("m*").first
39
+ end
40
+
41
+ def rdata_to_string #:nodoc: all
42
+ return "#{[@dhcid_data.to_s].pack("m*").gsub("\n", "")}"
43
+ end
44
+
45
+ def encode_rdata(msg, canonical=false) #:nodoc: all
46
+ msg.put_bytes(@dhcid_data)
47
+ end
48
+
49
+ def self.decode_rdata(msg) #:nodoc: all
50
+ dhcid_data, = msg.get_bytes()
51
+ return self.new([dhcid_data])
52
+ end
53
+ end
54
+ end
55
+ end
@@ -30,7 +30,11 @@ module Dnsruby
30
30
  end
31
31
 
32
32
  def from_string(input) #:nodoc: all
33
- @cpu, @os = input.split(" ")
33
+ cpu, os = input.split(" ")
34
+ cpu.sub!(/^\"/, "")
35
+ @cpu = cpu.sub(/\"$/, "")
36
+ os.sub!(/^\"/, "")
37
+ @os = os.sub(/\"$/, "")
34
38
  end
35
39
 
36
40
  def rdata_to_string #:nodoc: all
@@ -0,0 +1,138 @@
1
+
2
+ #--
3
+ #Copyright 2009 Nominet UK
4
+ #
5
+ #Licensed under the Apache License, Version 2.0 (the "License");
6
+ #you may not use this file except in compliance with the License.
7
+ #You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ #Unless required by applicable law or agreed to in writing, software
12
+ #distributed under the License is distributed on an "AS IS" BASIS,
13
+ #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ #See the License for the specific language governing permissions and
15
+ #limitations under the License.
16
+ #++
17
+ module Dnsruby
18
+ class RR
19
+ class HIP < RR
20
+
21
+ ClassValue = nil #:nodoc: all
22
+ TypeValue = Types::HIP #:nodoc: all
23
+
24
+ #An 8-bit length for the HIT field
25
+ attr_accessor :hit_length
26
+ #The PK algorithm used :
27
+ # 0 - no key present
28
+ # 1 - DSA key present
29
+ # 2 - RSA key present
30
+ attr_accessor :pk_algorithm
31
+ #An 8-bit length for the Public Key field
32
+ attr_accessor :pk_length
33
+
34
+ #An array of Rendezvous Servers
35
+ attr_accessor :rsvs
36
+
37
+ def from_data(data) #:nodoc: all
38
+ @rsvs=[]
39
+ @hit_length = data[0]
40
+ @pk_algorithm = data[1]
41
+ @pk_length = data[2]
42
+ @hit = data[3]
43
+ @public_key = data[4]
44
+ @rsvs = data[5]
45
+ end
46
+
47
+ def from_hash(hash)
48
+ @rsvs=[]
49
+ @hit_length = hash[:hit_length]
50
+ @pk_algorithm = hash[:pk_algorithm]
51
+ @pk_length = hash[:pk_length]
52
+ @hit = hash[:hit]
53
+ @public_key = hash[:public_key]
54
+ if (hash[:rsvs])
55
+ hash[:rsvs].each {|rsv|
56
+ @rsvs.push(Name.create(rsv))
57
+ }
58
+ end
59
+ end
60
+
61
+ #HIT field - stored in binary : client methods should handle base16(hex) encoding
62
+ def hit_string
63
+ # Return hex value
64
+ [@hit.to_s].pack("H*").gsub("\n", "")
65
+ end
66
+ def hit_from_string(hit_text)
67
+ # Decode the hex value
68
+ hit_text.gsub!(/\n/, "")
69
+ hit_text.gsub!(/ /, "")
70
+ return hit_text.unpack("H*")[0]
71
+ end
72
+
73
+ #Public Key field - presentation format is base64 - public_key methods reused from IPSECKEY
74
+ def public_key_string
75
+ [@public_key.to_s].pack("m*").gsub("\n", "")
76
+ end
77
+
78
+ def public_key_from_string(key_text)
79
+ key_text.gsub!(/\n/, "")
80
+ key_text.gsub!(/ /, "")
81
+ return key_text.unpack("m*")[0]
82
+ end
83
+
84
+ def from_string(input)
85
+ @rsvs=[]
86
+ if (input.length > 0)
87
+ split = input.split(" ")
88
+
89
+ @pk_algorithm = split[0].to_i
90
+ @hit = hit_from_string(split[1])
91
+ @hit_length = @hit.length
92
+ @public_key = public_key_from_string(split[2])
93
+ @pk_length = @public_key.length
94
+
95
+ # Now load in any RSVs there may be
96
+ count = 3
97
+ while (split[count])
98
+ @rsvs.push(Name.create(split[count]))
99
+ count += 1
100
+ end
101
+
102
+ end
103
+ end
104
+
105
+ def rdata_to_string #:nodoc: all
106
+ ret = "#{@pk_algorithm} #{hit_string} #{public_key_string}"
107
+ @rsvs.each {|rsv|
108
+ ret += " #{rsv}"
109
+ }
110
+ return ret
111
+ end
112
+
113
+ def encode_rdata(msg, canonical=false) #:nodoc: all\
114
+ msg.put_pack('ccC', @hit_length, @pk_algorithm, @pk_length)
115
+ msg.put_bytes(@hit)
116
+ msg.put_bytes(@public_key)
117
+ @rsvs.each {|rsv|
118
+ # RSVs MUST NOT be compressed
119
+ msg.put_name(rsv, true)
120
+ }
121
+ end
122
+
123
+ def self.decode_rdata(msg) #:nodoc: all
124
+ hit_length, pk_algorithm, pk_length = msg.get_unpack('ccC')
125
+ hit = msg.get_bytes(hit_length)
126
+ public_key = msg.get_bytes(pk_length)
127
+ rsvs = []
128
+ # Load in the RSV names, if there are any
129
+ while (msg.has_remaining)
130
+ name = msg.get_name
131
+ rsvs.push(name)
132
+ end
133
+ return self.new(
134
+ [hit_length, pk_algorithm, pk_length, hit, public_key, rsvs])
135
+ end
136
+ end
137
+ end
138
+ end
@@ -17,9 +17,9 @@ module Dnsruby
17
17
  class RR
18
18
  ClassInsensitiveTypes = [
19
19
  NS, CNAME, DNAME, DNSKEY, SOA, PTR, HINFO, MINFO, MX, TXT,
20
- ISDN, MB, MG, MR, NAPTR, NSAP, OPT, RP, RT, X25,
20
+ ISDN, MB, MG, MR, NAPTR, NSAP, OPT, RP, RT, X25, KX,
21
21
  SPF, CERT, LOC, TSIG, TKEY, ANY, RRSIG, NSEC, DS, NSEC3,
22
- NSEC3PARAM, DLV, SSHFP
22
+ NSEC3PARAM, DLV, SSHFP, IPSECKEY, HIP, DHCID
23
23
  ] #:nodoc: all
24
24
 
25
25
  # module IN contains ARPA Internet specific RRs
@@ -0,0 +1,143 @@
1
+ #--
2
+ #Copyright 2009 Nominet UK
3
+ #
4
+ #Licensed under the Apache License, Version 2.0 (the "License");
5
+ #you may not use this file except in compliance with the License.
6
+ #You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ #Unless required by applicable law or agreed to in writing, software
11
+ #distributed under the License is distributed on an "AS IS" BASIS,
12
+ #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ #See the License for the specific language governing permissions and
14
+ #limitations under the License.
15
+ #++
16
+ module Dnsruby
17
+ class RR
18
+ class IPSECKEY < RR
19
+
20
+ ClassValue = nil #:nodoc: all
21
+ TypeValue = Types::IPSECKEY #:nodoc: all
22
+
23
+ #An 8-bit precedence for this field. Lower values are preferred.
24
+ attr_accessor :precedence
25
+ #Specifies the type of gateway :
26
+ # 0 - no gateway present
27
+ # 1 - 4 byte IPv4 address present
28
+ # 2 - 16 byte IPv6 address present
29
+ # 3 - wire-encoded domain name present
30
+ attr_accessor :gateway_type
31
+ #The algorithm used by this key :
32
+ # 0 - no key present
33
+ # 1 - DSA key present
34
+ # 2 - RSA key present
35
+ attr_accessor :algorithm
36
+ #The gateway. May either be a 32-bit network order IPv4 address, or a
37
+ #128-bit IPv6 address, or a domain name, or may not be present.
38
+ attr_accessor :gateway
39
+
40
+ def from_data(data) #:nodoc: all
41
+ @precedence = data[0]
42
+ @gateway_type = data[1]
43
+ @algorithm = data[2]
44
+ @public_key = nil
45
+ @gateway = load_gateway_from_string(@gateway_type, data[3])
46
+ if (@gateway)
47
+ @public_key = data[4]
48
+ else
49
+ @public_key = data[3]
50
+ end
51
+ end
52
+
53
+ def from_hash(hash)
54
+ @precedence = hash[:precedence]
55
+ @gateway_type = hash[:gateway_type]
56
+ @algorithm = hash[:algorithm]
57
+ @gateway = load_gateway_from_string(@gateway_type, hash[:gateway])
58
+ @public_key = hash[:public_key]
59
+ end
60
+
61
+ def load_gateway_from_string(gateway_type, s)
62
+ gateway = nil
63
+ if (gateway_type == 0)
64
+ gateway = nil
65
+ elsif (gateway_type == 1)
66
+ # Load IPv4 gateway
67
+ gateway = IPv4.create(s)
68
+ elsif (gateway_type == 2)
69
+ # Load IPv6 gateway
70
+ gateway = IPv6.create(s)
71
+ else
72
+ # Load gateway domain name
73
+ gateway = Name.create(s)
74
+ end
75
+ return gateway
76
+ end
77
+
78
+ def public_key_string
79
+ [@public_key.to_s].pack("m*").gsub("\n", "")
80
+ end
81
+
82
+ def public_key_from_string(key_text)
83
+ key_text.gsub!(/\n/, "")
84
+ key_text.gsub!(/ /, "")
85
+ return key_text.unpack("m*")[0]
86
+ end
87
+
88
+ def from_string(input)
89
+ if (input.length > 0)
90
+ split = input.split(" ")
91
+
92
+ @precedence = split[0].to_i
93
+ @gateway_type = split[1].to_i
94
+ @algorithm = split[2].to_i
95
+
96
+ @gateway = load_gateway_from_string(@gateway_type, split[3])
97
+
98
+ @public_key = public_key_from_string(split[4])
99
+ end
100
+ end
101
+
102
+ def rdata_to_string #:nodoc: all
103
+ ret = "#{@precedence} #{@gateway_type} #{@algorithm} "
104
+ if (@gateway_type > 0)
105
+ ret += "#{@gateway} "
106
+ end
107
+ ret += "#{public_key_string()}"
108
+ return ret
109
+ end
110
+
111
+ def encode_rdata(msg, canonical=false) #:nodoc: all
112
+ msg.put_pack('ccc', @precedence, @gateway_type, @algorithm)
113
+ if ([1,2].include?@gateway_type)
114
+ msg.put_bytes(@gateway.address)
115
+ end
116
+ if (@gateway_type == 3)
117
+ msg.put_name(@gateway, true) # gateway MUST NOT be compressed
118
+ end
119
+ msg.put_bytes(@public_key)
120
+ end
121
+
122
+ def self.decode_rdata(msg) #:nodoc: all
123
+ precedence, gateway_type, algorithm = msg.get_unpack('ccc')
124
+ gateway = nil
125
+ if (gateway_type == 1)
126
+ gateway = IPv4.new(msg.get_bytes(4))
127
+ elsif (gateway_type == 2)
128
+ gateway = IPv6.new(msg.get_bytes(16))
129
+ elsif (gateway_type == 3)
130
+ gateway = msg.get_name
131
+ end
132
+ public_key = msg.get_bytes
133
+ if (gateway_type == 0)
134
+ return self.new(
135
+ [precedence, gateway_type, algorithm, public_key])
136
+ else
137
+ return self.new(
138
+ [precedence, gateway_type, algorithm, gateway, public_key])
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end