From ff9af3de9b3037be4ba4899d8b7df192fcbce336 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Mon, 2 Jan 2023 22:42:26 +0100 Subject: [PATCH] Add attic These files are not relevant at all, but helped during research, development, debugging. Hence, don't throw them away, but move them a bit more out of sight. --- attic/debug_toolbar_resources.txt | 2 ++ attic/encryption_test.py | 49 +++++++++++++++++++++++++++++++ attic/example_mysql_config | 7 +++++ 3 files changed, 58 insertions(+) create mode 100644 attic/debug_toolbar_resources.txt create mode 100755 attic/encryption_test.py create mode 100644 attic/example_mysql_config diff --git a/attic/debug_toolbar_resources.txt b/attic/debug_toolbar_resources.txt new file mode 100644 index 0000000..2c35392 --- /dev/null +++ b/attic/debug_toolbar_resources.txt @@ -0,0 +1,2 @@ +https://django-debug-toolbar.readthedocs.io/en/latest/installation.html +https://stackoverflow.com/questions/6548947/how-can-django-debug-toolbar-be-set-to-work-for-just-some-users/6549317#6549317 diff --git a/attic/encryption_test.py b/attic/encryption_test.py new file mode 100755 index 0000000..4c10295 --- /dev/null +++ b/attic/encryption_test.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import django +import timeit + +os.environ.setdefault( + "DJANGO_SETTINGS_MODULE", "ivatar.settings" +) # pylint: disable=wrong-import-position +django.setup() # pylint: disable=wrong-import-position + +from ivatar.ivataraccount.models import ConfirmedEmail, APIKey +from simplecrypt import decrypt +from binascii import unhexlify + +digest = None +digest_sha256 = None + + +def get_digest_sha256(): + digest_sha256 = ConfirmedEmail.objects.first().encrypted_digest_sha256( + secret_key=APIKey.objects.first() + ) + return digest_sha256 + + +def get_digest(): + digest = ConfirmedEmail.objects.first().encrypted_digest( + secret_key=APIKey.objects.first() + ) + return digest + + +def decrypt_digest(): + return decrypt(APIKey.objects.first().secret_key, unhexlify(digest)) + + +def decrypt_digest_256(): + return decrypt(APIKey.objects.first().secret_key, unhexlify(digest_sha256)) + + +digest = get_digest() +digest_sha256 = get_digest_sha256() + +print("Encrypt digest: %s" % timeit.timeit(get_digest, number=1)) +print("Encrypt digest_sha256: %s" % timeit.timeit(get_digest_sha256, number=1)) +print("Decrypt digest: %s" % timeit.timeit(decrypt_digest, number=1)) +print("Decrypt digest_sha256: %s" % timeit.timeit(decrypt_digest_256, number=1)) diff --git a/attic/example_mysql_config b/attic/example_mysql_config new file mode 100644 index 0000000..a0504e8 --- /dev/null +++ b/attic/example_mysql_config @@ -0,0 +1,7 @@ +DATABASES['default'] = { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'libravatar', + 'USER': 'libravatar', + 'PASSWORD': 'libravatar', + 'HOST': 'localhost', +}