diff --git a/openviking/crypto/encryptor.py b/openviking/crypto/encryptor.py index ca6609eb..cf99a78e 100644 --- a/openviking/crypto/encryptor.py +++ b/openviking/crypto/encryptor.py @@ -108,14 +108,16 @@ async def decrypt(self, account_id: str, ciphertext: bytes) -> bytes: Returns: Decrypted plaintext content """ - # 1. Check magic number - if len(ciphertext) < MAGIC_LENGTH: - raise InvalidMagicError("Ciphertext too short") - + # 1. Check magic number (check prefix first, before length) + # This ensures plaintext files (including empty/short ones) are + # returned as-is instead of raising "Ciphertext too short". if not ciphertext.startswith(MAGIC): # Unencrypted file, return directly return ciphertext + if len(ciphertext) < MAGIC_LENGTH: + raise InvalidMagicError("Ciphertext too short") + try: # 2. Parse Envelope (