예제 #1
0
    def export(self, dbg_info: DebugInfo = DebugInfo.disabled()) -> bytes:
        """Serialization to binary representation.

        :param dbg_info: instance allowing to provide debug info about exported data
        :return: binary representation of the region (serialization).
        """
        result = super().export()
        # KIB
        kib_data = self._kib.export()
        dbg_info.append_binary_section("BEE-KIB (non-crypted)", kib_data)
        aes = AES.new(self._sw_key, AES.MODE_ECB)
        result += aes.encrypt(kib_data)
        # padding
        result = extend_block(result, self.PRDB_OFFSET)
        # PRDB
        prdb_data = self._prdb.export()
        dbg_info.append_binary_section("BEE-PRDB (non-crypted)", prdb_data)
        aes = AES.new(self._kib.kib_key, AES.MODE_CBC, self._kib.kib_iv)
        result += aes.encrypt(prdb_data)
        # padding
        return extend_block(result, self.SIZE)
예제 #2
0
def test_add_padding_invalid_input():
    """Test invalid inputs for misc.align_block()"""
    # negative length
    with pytest.raises(AssertionError):
        extend_block(b'', -1)
    # length < current length
    with pytest.raises(AssertionError):
        extend_block(b'\x00\x00', 1)
    # padding > 255
    with pytest.raises(AssertionError):
        extend_block(b'\x00\x00', 1, 256)
    # padding < 0
    with pytest.raises(AssertionError):
        extend_block(b'\x00\x00', 1, -1)
예제 #3
0
파일: test_csf.py 프로젝트: vhamersky/spsdk
def test_SegCSF_export_parse():
    obj = SegCSF(enabled=True)
    obj.append_command(
        CmdWriteData(ops=EnumWriteOps.WRITE_VALUE,
                     data=[(0x30340004, 0x4F400005)]))

    data = obj.export()
    csf_parsed = SegCSF.parse(data)
    assert data == csf_parsed.export()

    # with padding
    obj.padding_len = 0x10
    assert obj.export() == extend_block(data, obj.size + 0x10)
예제 #4
0
파일: bee.py 프로젝트: AdrianCano-01/spsdk
 def export(self) -> bytes:
     """:return: binary representation of the region (serialization)."""
     result = super().export()
     result += pack(
         self._struct_format(),
         self.TAGL,
         self.TAGH,
         self.VERSION,
         self.fac_count,
         self._start_addr,
         self._end_addr,
         self.mode,
         self.lock_options,
         self.counter[::-1],  # bytes swapped: reversed order
         b'\x00' * 32)
     for fac in self.fac_regions:
         result += fac.export()
     result = extend_block(result, self.SIZE)
     return result
예제 #5
0
def test_add_padding(test_input: bytes, length: int, padding: int, expected: bytes) -> None:
    """Test misc.add_padding()"""
    data = extend_block(test_input, length, padding)
    assert data == expected