From cf06534d6d9ea70f9fa1183a5c6887364e20529e Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 14 Apr 2020 18:29:56 +0300 Subject: [PATCH] Serializers: handle our variant of b64 (no padding, urlsafe). --- django_etesync/serializers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django_etesync/serializers.py b/django_etesync/serializers.py index 127d88c..37b119e 100644 --- a/django_etesync/serializers.py +++ b/django_etesync/serializers.py @@ -29,10 +29,11 @@ def generate_rev_uid(length=32): class BinaryBase64Field(serializers.Field): def to_representation(self, value): - return base64.b64encode(value).decode('ascii') + return base64.urlsafe_b64encode(value).decode('ascii') def to_internal_value(self, data): - return base64.b64decode(data) + data += "=" * ((4 - len(data) % 4) % 4) + return base64.urlsafe_b64decode(data) class CollectionEncryptionKeyField(BinaryBase64Field):