Modify binary64 field to support binary renderers/parsers

Fixes 39c1dfc53c30e65bcbff9e0ba0bb07bfc8bfc577
master
Tom Hacohen 4 years ago
parent 453275eadf
commit fbf5552a62

@ -58,19 +58,16 @@ def b64decode(data):
class BinaryBase64Field(serializers.Field): class BinaryBase64Field(serializers.Field):
def to_representation(self, value): def to_representation(self, value):
return b64encode(value) if self.context.get('supports_binary', False):
return value
def to_internal_value(self, data): else:
return b64decode(data) return b64encode(value)
# This field does nothing to the data. It's useful for raw binary data
class RawField(serializers.Field):
def to_representation(self, value):
return value
def to_internal_value(self, data): def to_internal_value(self, data):
return data if isinstance(data, bytes):
return data
else:
return b64decode(data)
class CollectionEncryptionKeyField(BinaryBase64Field): class CollectionEncryptionKeyField(BinaryBase64Field):
@ -422,7 +419,7 @@ class AuthenticationLoginSerializer(serializers.Serializer):
class AuthenticationLoginInnerSerializer(AuthenticationLoginChallengeSerializer): class AuthenticationLoginInnerSerializer(AuthenticationLoginChallengeSerializer):
challenge = RawField() challenge = BinaryBase64Field()
host = serializers.CharField() host = serializers.CharField()
action = serializers.CharField() action = serializers.CharField()

Loading…
Cancel
Save