Module: DRM::Tem

Defined in:
lib/drm/tem.rb

Class Method Summary collapse

Class Method Details

.subkey_proc_for_tem_proc(tem_proc) ⇒ Object

produces a subkey_proc(metadata, index) that works by calling a TEM with tem_proc tem_proc must be obtained by calling tem_proc_for_filekey



29
30
31
32
33
34
35
36
# File 'lib/drm/tem.rb', line 29

def self.subkey_proc_for_tem_proc(tem_proc)
  Proc.new do |, index|
    index_str = [0, 0] + Tem::Session.to_tem_ushort(index)
    tem_proc.body[tem_proc.label_address(:key_index), index_str.length] = index_str
    # TODO: more elegant solution than $tem
    $tem.execute(tem_proc).pack('C*')
  end
end

.tem_proc_for_filekey(filekey, pubek) ⇒ Object

produces a TEM procedure which yields the subkeys for filekey the procedure is sealed with the TEM public key pubek



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/drm/tem.rb', line 8

def self.tem_proc_for_filekey(filekey, pubek)
  key_proc = Tem::Session.assemble do |p|
    p.ldbc filekey.length + 4
    p.outnew
    p.mdfxb :from => :filekey, :size => filekey.length + 4, :to => (1 << 16) - 1
    p.halt
    p.label :filekey
    p.immed :ubyte, filekey.unpack('C*')
    p.label :key_index
    p.filler :ubyte, 2
    p.filler :ushort, 2
    p.label :end_of_hash
    p.stack
    p.extra 8
  end
  key_proc.seal pubek, :filekey, :key_index
  return key_proc
end