Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions openviking/crypto/encryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
Loading