def __init__(self, content: Optional[dict] = None, filename: Optional[str] = None, data: Optional[bytes] = None, thumbnail: Optional[bytes] = None): super().__init__(content, ContentType.IMAGE, filename=filename, data=data) self.__thumbnail = thumbnail if thumbnail is not None: self['thumbnail'] = base64_encode(data=thumbnail)
def __init__(self, content: Optional[dict] = None, filename: Optional[str] = None, data: Optional[bytes] = None, snapshot: Optional[bytes] = None): super().__init__(content, ContentType.VIDEO, filename=filename, data=data) self.__snapshot = snapshot if snapshot is not None: self['snapshot'] = base64_encode(data=snapshot)
def __init__(self, content: Optional[dict] = None, content_type: Union[ContentType, int] = 0, filename: Optional[str] = None, data: Optional[bytes] = None): if content is None: if content_type == 0: content_type = ContentType.FILE super().__init__(content_type=content_type) else: super().__init__(content=content) self.__attachment = data # attachment (file data) self.__password = None # symmetric key for decryption # set values to inner dictionary if filename is not None: self['filename'] = filename if data is not None: self['data'] = base64_encode(data=data)
def snapshot(self, small_image: bytes): self.__snapshot = small_image if small_image is None: self.pop('snapshot', None) else: self['snapshot'] = base64_encode(small_image)
def thumbnail(self, small_image: bytes): self.__thumbnail = small_image if small_image is None: self.pop('thumbnail', None) else: self['thumbnail'] = base64_encode(small_image)
def data(self, attachment: bytes): self.__attachment = attachment if attachment is None: self.pop('data', None) else: self['data'] = base64_encode(attachment)
def encode_signature(self, signature: bytes, msg: SecureMessage) -> str: return base64_encode(data=signature)
def encode_key(self, data: bytes, msg: InstantMessage) -> str: assert not is_broadcast( msg=msg), 'broadcast message has no key: %s' % msg return base64_encode(data=data)
def encode_data(self, data: bytes, msg: InstantMessage) -> str: if is_broadcast(msg=msg): # broadcast message content will not be encrypted (just encoded to JsON), # so no need to encode to Base64 here return utf8_decode(data=data) return base64_encode(data=data)