File: //var/opt/nydus/ops/primordial/__pycache__/encryptor.cpython-39.pyc
a
�,�h�, � @ s� d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm Z m
Z
mZmZ d dl
mZ d dlmZ d dlmZmZ d dlmZmZ d d lmZmZ e ed
�dd�Zeeef ed
�dd�ZG dd� d�ZG dd� d�ZG dd� d�Z dS )� N)� b64decode� b64encode)�Path)�AnyStr�Optional�Union�cast)�x509)�Fernet)�hashes�
serialization)�MGF1�OAEP)�aes_cbc_pkcs7_encrypt�aes_cbc_pkcs7_decrypt)�data�returnc C s t | t�r| �d�} tt| �S )a
Convert a Python `str` object to a `bytes` object. If the parameter is already a `bytes` object, return it
unmodified.
:param data: The object to be converted
:return: The converted object, or the original object if it was not a `str` object
�utf-8)�
isinstance�str�encoder �bytes)r � r �E/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/primordial/encryptor.py�_make_bytes s
r )�key_pathr c C sB | du rt d��t| t�r"t| �} | �� s:t dj| d���| �� S )a.
Convenience function to load the content of a key or cert file and return its contents.
:param key_path: Path to the key/cert file to be loaded
:return: The file contents as a bytes object
:raises: ValueError if the key_path parameter is None of doesn't point to an existing file
Nz!key_path parameter cannot be Nonez$key path '{key_path}' does not exist�r )�
ValueErrorr r r �is_file�format�
read_bytesr r r r �load_key_content! s
r! c @ s<