def encode_dumb(data, mode=None):
    if not mode:
        mode = mode_salsa20(random.choice(list(salsa20_keys.keys())))
        #mode = mode_normal()
    return (b'BLTE'  # magic
            + bin.BE_uint32_t(0)  # headerSize
            + mode(data))
예제 #2
0
 def install_data(self):
   # todo: obviously bogus
   return ( b'IN'
          + bin.uint8_t (1)     # version
          + bin.uint8_t (0x10)  # hashSize
          + bin.BE_uint16_t (0) # num_tags
          + bin.BE_uint32_t (0) # num_entries
          )
예제 #3
0
 def encoding_data(self):
   def sort_key(entry):
     #! \todo is this encoded_hash or raw_hash?
     return entry.encoded_hash
   self.encodings.sort(key=sort_key)
   
   # todo: multiple keys per entry (-> non-fixed size), should rather
   #       iterate all encodings and chunk while iterating
   entry_size = ( 1     # uint8_t keyCount
                + 5     # uint40_t fileSize
                + 0x10  # char[16] contentHash
                + 0x10  # char[16][keyCount=1] encodedHashes
                )
   entry_count = len(self.encodings)
   block_size = 4096
   entries_per_block = int(block_size / entry_size)
   blocks = list(chunk (self.encodings, entries_per_block))
   #assert (sum(len(blocks)) == len(self.encodings)
            
   string_block_a = bytes()
   blocks_a_register = bytes()
   blocks_a = bytes()
   blocks_a_count = 0
   blocks_b_register = bytes()
   blocks_b = bytes()
   blocks_b_count = 0
   string_block_b = b'b:{*=n}'
   
   for block in blocks:
     block_a_data = bytes()
     for entry in block:
       block_a_data += ( bin.uint8_t (1)                # 00 number of keys
                       + bin.BE_uint40_t (entry.size)   # 01 fileSize
                       + entry.raw_hash                 # 06 raw hash
                       + entry.encoded_hash             # 16 encoded hashes
                       )                                # 26
     block_a_data += b'\0' * (block_size - len(block_a_data))
     
     blocks_a += block_a_data
     blocks_a_register += ( block[0].raw_hash
                          + bin.hex (md5 (block_a_data))
                          )
     blocks_a_count += 1
     
   block_b_eof = b'\0' * 16 + b'\xff' * 4
   for block in []:
     block_b_data = bytes()
     for entry in block:
       block_b_data += ( entry.hash
                       + bin.BE_uint32_t (stringIndex)
                       + bin.BE_uint40_t (size)
                       )
     if True: # is_last:
       block_b_data += block_b_eof
     block_b_data += b'\0' * (block_size - len(block_b_data))
     
     blocks_b += block_b_data
     blocks_b_register += ( block[0].hash
                          + bin.hex (md5 (block_b_data))
                          )
     blocks_b_count += 1
     
   header = ( b'EN'                                  # 00 magic
            + bin.uint8_t (0)                        # 02 version
            + bin.uint8_t (0x10)                     # 03 checksumSizeA
            + bin.uint8_t (0x10)                     # 04 checksumSizeB
            + bin.uint16_t (0)                       # 05 flagsA
            + bin.uint16_t (0)                       # 07 flagsB
            + bin.BE_uint32_t (blocks_a_count)       # 09 numEntriesA
            + bin.BE_uint32_t (blocks_b_count)       # 0d numEntriesB
            + bin.BE_uint40_t (len (string_block_a)) # 11 stringBlockSize
                                                     # 16
            )
              
   return ( header
          + string_block_a   
          + blocks_a_register
          + blocks_a
          + blocks_b_register
          + blocks_b
          + string_block_b
          )
예제 #4
0
 def index_entry(entry):
   return ( entry.header_hash_md5   # md5 == 16 bytes
          + bin.BE_uint32_t (entry.encoded_size)
          + bin.BE_uint32_t (entry.offset_to_blte_encoded_data_in_archive)
          )
def hashpath(data):
  c, b = hashlittle2(data.upper().replace('/', '\\'))
  return (bin.BE_uint32_t(c) + bin.BE_uint32_t(b))[::-1]