Class: Dnsruby::RR::IPSECKEY

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

Constant Summary collapse

ClassValue =

:nodoc: all

nil
TypeValue =

:nodoc: all

Types::IPSECKEY

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

#algorithmObject

The algorithm used by this key :

0 - no key present
1 - DSA key present
2 - RSA key present


35
36
37
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 35

def algorithm
  @algorithm
end

#gatewayObject

The gateway. May either be a 32-bit network order IPv4 address, or a 128-bit IPv6 address, or a domain name, or may not be present.



38
39
40
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 38

def gateway
  @gateway
end

#gateway_typeObject

Specifies the type of gateway :

0 - no gateway present
1 - 4 byte IPv4 address present
2 - 16 byte IPv6 address present
3 - wire-encoded domain name present


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

def gateway_type
  @gateway_type
end

#precedenceObject

An 8-bit precedence for this field. Lower values are preferred.



24
25
26
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 24

def precedence
  @precedence
end

Class Method Details

.decode_rdata(msg) ⇒ Object

:nodoc: all



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 122

def self.decode_rdata(msg) #:nodoc: all
  precedence, gateway_type, algorithm = msg.get_unpack('ccc')
  gateway = nil
  if (gateway_type == 1)
    gateway = IPv4.new(msg.get_bytes(4))
  elsif (gateway_type == 2)
    gateway = IPv6.new(msg.get_bytes(16))
  elsif (gateway_type == 3)
    gateway = msg.get_name
  end
  public_key = msg.get_bytes
  if (gateway_type == 0)
    return self.new(
      [precedence, gateway_type, algorithm, public_key])
  else
    return self.new(
      [precedence, gateway_type, algorithm, gateway, public_key])
  end
end

Instance Method Details

#encode_rdata(msg, canonical = false) ⇒ Object

:nodoc: all



111
112
113
114
115
116
117
118
119
120
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 111

def encode_rdata(msg, canonical=false) #:nodoc: all
  msg.put_pack('ccc', @precedence, @gateway_type, @algorithm)
  if ([1,2].include?@gateway_type)
    msg.put_bytes(@gateway.address)
  end
  if (@gateway_type == 3)
    msg.put_name(@gateway, true) # gateway MUST NOT be compressed
  end
  msg.put_bytes(@public_key)
end

#from_data(data) ⇒ Object

:nodoc: all



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 40

def from_data(data) #:nodoc: all
  @precedence = data[0]
  @gateway_type = data[1]
  @algorithm = data[2]
  @public_key = nil
  @gateway = load_gateway_from_string(@gateway_type, data[3])
  if (@gateway)
    @public_key = data[4]
  else
    @public_key = data[3]
  end
end

#from_hash(hash) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 53

def from_hash(hash)
  @precedence = hash[:precedence]
  @gateway_type = hash[:gateway_type]
  @algorithm = hash[:algorithm]
  @gateway = load_gateway_from_string(@gateway_type, hash[:gateway])
  @public_key = hash[:public_key]
end

#from_string(input) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 88

def from_string(input)
  if (input.length > 0)
    split = input.split(" ")

    @precedence = split[0].to_i
    @gateway_type = split[1].to_i
    @algorithm = split[2].to_i

    @gateway = load_gateway_from_string(@gateway_type, split[3])

    @public_key = public_key_from_string(split[4])
  end
end

#load_gateway_from_string(gateway_type, s) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 61

def load_gateway_from_string(gateway_type, s)
  gateway = nil
  if (gateway_type == 0)
    gateway = nil
  elsif (gateway_type == 1)
    #  Load IPv4 gateway
    gateway = IPv4.create(s)
  elsif (gateway_type == 2)
    #  Load IPv6 gateway
    gateway = IPv6.create(s)
  else
    #  Load gateway domain name
    gateway = Name.create(s)
  end
  return gateway
end

#public_key_from_string(key_text) ⇒ Object



82
83
84
85
86
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 82

def public_key_from_string(key_text)
  key_text.gsub!(/\n/, "")
  key_text.gsub!(/ /, "")
  return key_text.unpack("m*")[0]
end

#public_key_stringObject



78
79
80
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 78

def public_key_string
  [@public_key.to_s].pack("m*").gsub("\n", "")
end

#rdata_to_stringObject

:nodoc: all



102
103
104
105
106
107
108
109
# File 'lib/dnsruby/resource/IPSECKEY.rb', line 102

def rdata_to_string #:nodoc: all
  ret = "#{@precedence} #{@gateway_type} #{@algorithm} "
  if (@gateway_type > 0)
    ret += "#{@gateway} "
  end
  ret += "#{public_key_string()}"
  return ret
end