�
J�gU � �� � d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
mZmZmZ ddlmZmZ dd lmZ dd
lmZmZmZmZ ddlmZ ddlmZmZ dd
l m!Z!m"Z" ddl#m$Z$ dZ%n# e&$ rZ'e'Z%Y dZ'['ndZ'['ww xY w ej( e)� � Z* G d� d� � Z+ G d� d� � Z, G d� de� � Z- G d� d� � Z.dee/e0f de/fd�Z1de2de2fd�Z3dS )a
Utilities to perform encryption following the PDF standards.
The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
� N)�hexlify)�BOM_UTF16_BE��urandom)�Callable�Iterable�Type�Union� )�AccessPermission�EncryptionMethod)�
FPDFException)�Name� PDFObject� PDFString�build_obj_dict)�create_dictionary_string)�Cipher�modes)�AES128�AES256)�PKCS7c �f � e Zd ZdZdZdedefd�Zdedee fd�Z
dedeeef defd �Z
d
S )�ARC4az
This is a simplified version of the ARC4 (alleged RC4) algorithm,
created based on the following sources:
* Wikipedia article on RC4
* github.com/manojpandey/rc4 (MIT License)
* http://people.csail.mit.edu/rivest/pubs/RS14.pdf
Having this ARC4 implementation makes it possible to have basic
encryption functions without additional dependencies
� �key�returnc � � t |� � }t t | j � � � � }d}t | j � � D ]8}||| z |||z z | j z }|| || c||<