Module: TrisulRP::Keys
- Defined in:
- lib/trisulrp/keys.rb
Overview
Keys - Utilities to convert a key to a human readable string & back
Defined Under Namespace
Classes: ASNumber, HNumber, Host, HostInterface, Null, Port, Subnet
Instance Method Summary collapse
-
#get_labels_for_keys(conn, cgguid, key_arr) ⇒ Object
TrisulRP::Guids::CG_HOSTS, host_keys).
-
#make_key(readable) ⇒ Object
convert a key in human form into trisul key format.
-
#make_readable(keyform) ⇒ Object
convert a trisul key format into a human readable key [keyform] the key form.
Instance Method Details
#get_labels_for_keys(conn, cgguid, key_arr) ⇒ Object
TrisulRP::Guids::CG_HOSTS, host_keys)
host_names["0A.0A.18.E0"] = "demo.trisul.org" # ok
host_names["B1.01.8F.01"] = "B1.01.8F.01" # no label for this key
</code>
297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/trisulrp/keys.rb', line 297 def get_labels_for_keys(conn, cgguid, key_arr) req = mk_request(TRP::Message::Command::KEY_LOOKUP_REQUEST, :counter_group => cgguid, :keys => key_arr.uniq ) h = key_arr.inject({}) { |m,i| m.store(i,make_readable(i)); m } get_response(conn,req) do |resp| resp.key_details.each { |d| h.store(d.key,d.label) } end return h end |
#make_key(readable) ⇒ Object
convert a key in human form into trisul key format
- humanform
-
the human form of the key
Typical use
Used to convert a human form key into a Trisul Key format suitable for use with TRP requests
<code>
make_key("192.168.1.1") => "C0.A8.01.01"
</code>
Also see the inverse of this method make_readable
256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/trisulrp/keys.rb', line 256 def make_key(readable) [ TrisulRP::Keys::Port, TrisulRP::Keys::Host, TrisulRP::Keys::HostInterface, TrisulRP::Keys::Subnet, TrisulRP::Keys::ASNumber ].each do |kls| return kls.invert_xform(readable) if kls.is_human_form?(readable) end return readable end |
#make_readable(keyform) ⇒ Object
convert a trisul key format into a human readable key
- keyform
-
the key form
Typical use
Used to convert an IP / Port or any other trisul key into a readable form
<code>
make_readable("C0.A8.0C.A0") => "192.168.12.160"
make_readable("p-0016") => "Port-22"
</code>
Also see TrisulRP::Protocol::get_labels_for_keys to obtain a text name for the key
Also see the inverse of this method make_key which convert a readable string into a key suitable for use in TRP request messages.
If key type cannot be accurately guessed it returns the input
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/trisulrp/keys.rb', line 224 def make_readable(keyform) [ TrisulRP::Keys::Port, TrisulRP::Keys::Host, TrisulRP::Keys::HostInterface, TrisulRP::Keys::Subnet, TrisulRP::Keys::ASNumber ].each do |kls| return kls.xform(keyform) if kls.is_key_form?(keyform) end return keyform end |