From 5c13b626a8b86f8733d9e358cce4dca4dbd5857f Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 7 Apr 2021 17:18:09 +0200 Subject: [PATCH] Resolve tabbing/indentation issues --- djangoldp_webpushnotification/admin.py | 16 ++++---- .../management/commands/gen_vapid_key.py | 20 +++++----- djangoldp_webpushnotification/models.py | 37 ++++++++++--------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/djangoldp_webpushnotification/admin.py b/djangoldp_webpushnotification/admin.py index 324321c..74a4ed7 100644 --- a/djangoldp_webpushnotification/admin.py +++ b/djangoldp_webpushnotification/admin.py @@ -1,19 +1,19 @@ from django.contrib import admin from djangoldp.admin import DjangoLDPAdmin + from .models import VAPIDKeyset class VAPIDKeysetAdmin(DjangoLDPAdmin): - readonly_fields = ('public_key_view', 'private_key_view') + readonly_fields = ('public_key_view', 'private_key_view') - def public_key_view(self, obj): - return obj.public_key + def public_key_view(self, obj): + return obj.public_key - def private_key_view(self, obj): - return obj.private_key.tobytes() - - class Meta: - verbose_name = 'VAPID key-set' + def private_key_view(self, obj): + return obj.private_key.tobytes() + class Meta: + verbose_name = 'VAPID key-set' admin.site.register(VAPIDKeyset, VAPIDKeysetAdmin) diff --git a/djangoldp_webpushnotification/management/commands/gen_vapid_key.py b/djangoldp_webpushnotification/management/commands/gen_vapid_key.py index d959d20..ef8cbde 100644 --- a/djangoldp_webpushnotification/management/commands/gen_vapid_key.py +++ b/djangoldp_webpushnotification/management/commands/gen_vapid_key.py @@ -1,21 +1,21 @@ -import ecdsa -from ecdsa import SigningKey from base64 import urlsafe_b64encode +import ecdsa from django.core.management.base import BaseCommand from djangoldp_webpushnotification.models import VAPIDKeyset +from ecdsa import SigningKey class Command(BaseCommand): - help = "Generate VAPID key pair" + help = "Generate VAPID key pair" - def handle(self, *args, **options): - priv_key = SigningKey.generate(curve=ecdsa.NIST256p) + def handle(self, *args, **options): + priv_key = SigningKey.generate(curve=ecdsa.NIST256p) - VAPIDKeyset.objects.create( - private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=") - ) + VAPIDKeyset.objects.create( + private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=") + ) - self.stdout.write("VAPID Keyset succesfully generated") + self.stdout.write("VAPID Keyset succesfully generated") - exit(0) + exit(0) diff --git a/djangoldp_webpushnotification/models.py b/djangoldp_webpushnotification/models.py index de2e9dc..08cf378 100644 --- a/djangoldp_webpushnotification/models.py +++ b/djangoldp_webpushnotification/models.py @@ -1,24 +1,25 @@ -from ecdsa import SigningKey, NIST256p -from django.db import models from base64 import urlsafe_b64decode, urlsafe_b64encode +from django.db import models +from ecdsa import NIST256p, SigningKey + class VAPIDKeyset(models.Model): - private_key = models.BinaryField(max_length=43) + private_key = models.BinaryField(max_length=43) - def __str__(self): - return "public_key:{}... private_key:{}...".format( - self.public_key[:10], - self.private_key.tobytes()[:10] - ) + def __str__(self): + return "public_key:{}... private_key:{}...".format( + self.public_key[:10], + self.private_key.tobytes()[:10] + ) - @property - def public_key(self): - key_str = self.private_key.tobytes() - padding = len(key_str) % 4 - key_str += b"=" * padding - key = SigningKey.from_string( - urlsafe_b64decode(key_str), - curve=NIST256p - ).get_verifying_key() - return urlsafe_b64encode(b"\x04" + key.to_string()).strip(b"=") + @property + def public_key(self): + key_str = self.private_key.tobytes() + padding = len(key_str) % 4 + key_str += b"=" * padding + key = SigningKey.from_string( + urlsafe_b64decode(key_str), + curve=NIST256p + ).get_verifying_key() + return urlsafe_b64encode(b"\x04" + key.to_string()).strip(b"=")