Module: Tem::Toolkit
- Included in:
- Session
- Defined in:
- lib/tem/toolkit.rb
Instance Method Summary collapse
- #tk_delete_key(key_id, authz) ⇒ Object
- #tk_firmware_ver ⇒ Object
- #tk_gen_key(type = :asymmetric, authz = nil) ⇒ Object
- #tk_post_key(key, authz) ⇒ Object
- #tk_read_key(key_id, authz) ⇒ Object
Instance Method Details
#tk_delete_key(key_id, authz) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tem/toolkit.rb', line 65 def tk_delete_key(key_id, authz) del_sec = assemble do |s| s.ldbc :const => key_id s.authk :auth => :key_auth s.relk s.ldbc :const => 1 s.outnew s.ldbc :const => key_id s.outb s.halt s.label :key_auth s.data :tem_ubyte, authz s.stack 4 end execute del_sec end |
#tk_firmware_ver ⇒ Object
2 3 4 5 |
# File 'lib/tem/toolkit.rb', line 2 def tk_firmware_ver tag = get_tag return { :major => read_tem_ubyte(tag, 0), :minor => read_tem_ubyte(tag, 1) } end |
#tk_gen_key(type = :asymmetric, authz = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tem/toolkit.rb', line 7 def tk_gen_key(type = :asymmetric, authz = nil) gen_sec = assemble do |s| s.ldbc authz.nil? ? 24 : 4 s.outnew if authz.nil? # no authorization given, must generate one s.ldbc 20 s.ldwc :key_auth s.dupn :n => 2 s.rnd s.outvb end s.genkp :type => (type == :asymmetric) ? 0x00 : 0x80 s.authk :auth => :key_auth s.outw s.authk :auth => :key_auth s.outw s.halt s.label :key_auth if authz.nil? s.zeros :tem_ubyte, 20 else s.data :tem_ubyte, authz end s.stack 4 end kp_buffer = execute gen_sec keys_offset = authz.nil? ? 20 : 0 k1id = read_tem_ushort kp_buffer, keys_offset k2id = read_tem_ushort kp_buffer, keys_offset + 2 if type == :asymmetric return_val = { :pubk_id => k1id, :privk_id => k2id } else return_val = { :key_id => k1id } end return { :authz => authz.nil? ? kp_buffer[0...20] : authz }.merge!(return_val) end |
#tk_post_key(key, authz) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tem/toolkit.rb', line 83 def tk_post_key(key, authz) post_sec = assemble do |s| s.ldbc :const => 1 s.outnew s.ldwc :const => :key_data s.rdk s.authk :auth => :key_auth s.outb s.halt s.label :key_data s.data :tem_ubyte, key.to_tem_key s.label :key_auth s.data :tem_ubyte, authz s.stack 4 end id_string = execute post_sec return read_tem_ubyte(id_string, 0) end |
#tk_read_key(key_id, authz) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tem/toolkit.rb', line 46 def tk_read_key(key_id, authz) read_sec = assemble do |s| s.ldbc :const => key_id s.authk :auth => :key_auth s.ldkl s.outnew s.ldbc :const => key_id s.ldbc(-1) s.stk s.halt s.label :key_auth s.data :tem_ubyte, authz s.stack 4 end key_string = execute read_sec return read_tem_key(key_string, 0) end |