Modify binary64 field to support binary renderers/parsers
Fixes 39c1dfc53c30e65bcbff9e0ba0bb07bfc8bfc577
This commit is contained in:
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):
|
||||||
|
if self.context.get('supports_binary', False):
|
||||||
|
return value
|
||||||
|
else:
|
||||||
return b64encode(value)
|
return b64encode(value)
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
return b64decode(data)
|
if isinstance(data, bytes):
|
||||||
|
|
||||||
|
|
||||||
# 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):
|
|
||||||
return data
|
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…
Reference in New Issue
Block a user