assertion failure was a bit heavy-handed here. Raise error instead

This commit is contained in:
Emil Lerch 2022-01-06 12:11:30 -08:00
parent d64e567dbd
commit c5ffd71eed
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -105,7 +105,11 @@ pub fn decryptWithKey(allocator: std.mem.Allocator, key: [key_size]u8, data: []c
// deal with final block, PKCS#7 padding
in = @ptrCast(*const [block_size]u8, data[(current_block * block_size)..(((current_block + 1) * block_size) - 1)]);
ctx.decrypt(out[0..], in.*[0..]);
std.debug.assert(out[block_size - 1] <= block_size);
// Assertion was triggering when data was plain text
if (out[block_size - 1] > block_size) {
return error.DecryptionFailed;
}
// std.debug.assert(out[block_size - 1] <= block_size);
try decrypted.appendSlice(out[0 .. block_size - out[block_size - 1]]);
return decrypted.toOwnedSlice();
}