def total_head(self) -> bytes: """ `BAIDUPCS_PY_CRYPTO_MAGIC_CODE 32bytes` + `encrypt algorithm code 1bytes` + `nonce or iv 16bytes` + `total_origin_len 64bit` """ return (self._encrypted_baidupcs_py_crypto_magic_code + self.MAGIC_CODE + self._nonce_or_iv + u64_to_u8x8(self._total_origin_len))
def total_head(self) -> bytes: """ Version 1: aes256cbc_encrypt(`BAIDUPCS_PY_CRYPTO_MAGIC_CODE 32bytes`, encrypt_password, random_bytes(16, encrypt_password)) + `encrypt algorithm code 1bytes` + `nonce or iv 16bytes` + `total_origin_len 8bytes` Version 2: aes256cbc_encrypt( `BAIDUPCS_PY_CRYPTO_MAGIC_CODE 32bytes` + `encrypt algorithm code 1bytes` + `nonce_or_iv 16bytes` `total_origin_len 8bytes` ) + `salt 8bytes` Version 3: aes256cbc_encrypt( `BAIDUPCS_PY_CRYPTO_MAGIC_CODE 32bytes` + `encrypt algorithm code 1bytes` + `salt 8bytes` + `random padding 8bytes` `total_origin_len 8bytes` ) + `salt 8bytes` """ if self._total_head: return self._total_head assert len(self._salt) == 8 ori_head = padding_key( BAIDUPCS_PY_CRYPTO_MAGIC_CODE + self.MAGIC_CODE + self._salt + random_sys_bytes(8) + u64_to_u8x8(self._total_origin_len), PADDED_ENCRYPT_HEAD_LEN, value=b"", ) # AES256CBC Encrypt head self._total_head = (aes256cbc_encrypt( ori_head, self._encrypt_key_for_head, self._iv_for_head) + self._salt_for_head) return self._total_head
def test_u64_u8x8(): i = 2**32 b = u64_to_u8x8(i) x = u8x8_to_u64(b) assert i == x