Serializers: handle our variant of b64 (no padding, urlsafe).

master
Tom Hacohen 5 years ago
parent 9b13404ce7
commit cf06534d6d

@ -29,10 +29,11 @@ def generate_rev_uid(length=32):
class BinaryBase64Field(serializers.Field): class BinaryBase64Field(serializers.Field):
def to_representation(self, value): def to_representation(self, value):
return base64.b64encode(value).decode('ascii') return base64.urlsafe_b64encode(value).decode('ascii')
def to_internal_value(self, data): def to_internal_value(self, data):
return base64.b64decode(data) data += "=" * ((4 - len(data) % 4) % 4)
return base64.urlsafe_b64decode(data)
class CollectionEncryptionKeyField(BinaryBase64Field): class CollectionEncryptionKeyField(BinaryBase64Field):

Loading…
Cancel
Save