# Path: will/settings.py
# def auto_key():
# def import_settings(quiet=True):
#         DEPRECATED_BUT_MAPPED_SETTINGS = {
#             "USERNAME": "HIPCHAT_USERNAME",
#             "PASSWORD": "HIPCHAT_PASSWORD",
#             "V1_TOKEN": "HIPCHAT_V1_TOKEN",
#             "V2_TOKEN": "HIPCHAT_V2_TOKEN",
#             "TOKEN": "HIPCHAT_V1_TOKEN",
#             "ROOMS": "HIPCHAT_ROOMS",
#             "NAME": "HIPCHAT_NAME",
#             "HANDLE": "HIPCHAT_HANDLE",
#             "DEFAULT_ROOM": "HIPCHAT_DEFAULT_ROOM",
#             "SLACK_DEFAULT_ROOM": "SLACK_DEFAULT_CHANNEL",
#         }
#             IO_BACKENDS = []
# 
# Path: will/backends/encryption/base.py
# class WillBaseEncryptionBackend(object):
# 
#     def __init__(self, *args, **kwargs):
#         pass
# 
#     @staticmethod
#     def encrypt_to_b64(raw):
#         raise NotImplementedError
# 
#     @staticmethod
#     def decrypt_from_b64(enc):
#         raise NotImplementedError


import binascii
import hashlib
import logging
import os
import dill as pickle
from Crypto.Cipher import AES
from will import settings
from will.backends.encryption.base import WillBaseEncryptionBackend
'Encrypt stored data'




# pylint: disable=no-member

BS = 16
key = hashlib.sha256(settings.SECRET_KEY.encode("utf-8")).digest()


def pad(s: bytes) -> str:
    '''Ensure the data to be encrypted has sufficient padding.
    Arbitrarily adding ~ to the end, so your message better not end with ~.'''
    return "%s%s" % (s.decode("utf-8"), ((BS - len(s) % BS) * "~"))


def unpad(s: bytes) -> bytes:
    'Removes all ~ on the end of the message.'
    return s.rstrip(b'~')


class AESEncryption(WillBaseEncryptionBackend):
    'AES encryption backend'
    @staticmethod
    def encrypt_to_b64(raw):
        'encrypt and b64-encode data'
        try:
            enc = binascii.b2a_base64(pickle.dumps(raw, -1))

# Path: will/settings.py
# def auto_key():
# def import_settings(quiet=True):
#         DEPRECATED_BUT_MAPPED_SETTINGS = {
#             "USERNAME": "HIPCHAT_USERNAME",
#             "PASSWORD": "HIPCHAT_PASSWORD",
#             "V1_TOKEN": "HIPCHAT_V1_TOKEN",
#             "V2_TOKEN": "HIPCHAT_V2_TOKEN",
#             "TOKEN": "HIPCHAT_V1_TOKEN",
#             "ROOMS": "HIPCHAT_ROOMS",
#             "NAME": "HIPCHAT_NAME",
#             "HANDLE": "HIPCHAT_HANDLE",
#             "DEFAULT_ROOM": "HIPCHAT_DEFAULT_ROOM",
#             "SLACK_DEFAULT_ROOM": "SLACK_DEFAULT_CHANNEL",
#         }
#             IO_BACKENDS = []
# 
# Path: will/backends/encryption/base.py
# class WillBaseEncryptionBackend(object):
# 
#     def __init__(self, *args, **kwargs):
#         pass
# 
#     @staticmethod
#     def encrypt_to_b64(raw):
#         raise NotImplementedError
# 
#     @staticmethod
#     def decrypt_from_b64(enc):
#         raise NotImplementedError


# Path: will/backends/encryption/aes.py
import binascii
import hashlib
import logging
import os
import dill as pickle
from Crypto.Cipher import AES
from will import settings
from will.backends.encryption.base import WillBaseEncryptionBackend

'Encrypt stored data'




# pylint: disable=no-member

BS = 16
key = hashlib.sha256(settings.SECRET_KEY.encode("utf-8")).digest()


def pad(s: bytes) -> str:
    '''Ensure the data to be encrypted has sufficient padding.
    Arbitrarily adding ~ to the end, so your message better not end with ~.'''
    return "%s%s" % (s.decode("utf-8"), ((BS - len(s) % BS) * "~"))


def unpad(s: bytes) -> bytes:
    'Removes all ~ on the end of the message.'
    return s.rstrip(b'~')


class AESEncryption(WillBaseEncryptionBackend):
    'AES encryption backend'
    @staticmethod
    def encrypt_to_b64(raw):
        'encrypt and b64-encode data'
        try:
            enc = binascii.b2a_base64(pickle.dumps(raw, -1))

            if settings.ENABLE_INTERNAL_ENCRYPTION: