-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added image media message builder Initial support for encrypted media (recv ok) Moved proto to protocol_messages
- Loading branch information
Showing
10 changed files
with
216 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
yowsup/layers/protocol_media/protocolentities/builder_message_media_downloadable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# from yowsup.layers.protocol_media import mediacipher | ||
import tempfile | ||
import os | ||
class DownloadableMediaMessageBuilder(object): | ||
def __init__(self, downloadbleMediaMessageClass, jid, filepath): | ||
self.jid = jid | ||
self.filepath = filepath | ||
self.encryptedFilepath = None | ||
self.cls = downloadbleMediaMessageClass | ||
self.mediaKey = None | ||
self.attributes = {} | ||
self.mediaType = self.cls.__name__.split("DownloadableMediaMessageProtocolEntity")[0].lower() #ugly ? | ||
|
||
# def encrypt(self): | ||
# fd, encpath = tempfile.mkstemp() | ||
# mediaKey = os.urandom(112) | ||
# keys = mediacipher.getDerivedKeys(mediaKey) | ||
# out = mediacipher.encryptImage(self.filepath, keys) | ||
# with open(encImagePath, 'w') as outF: | ||
# outF.write(out) | ||
# | ||
# self.mediaKey = mediaKey | ||
# self.encryptedFilepath = encpath | ||
|
||
# def decrypt(self): | ||
# self.mediaKey = None | ||
# self.encryptedFilePath = None | ||
|
||
|
||
def setEncryptionData(self, mediaKey, encryptedFilepath): | ||
self.mediaKey = mediaKey | ||
self.encryptedFilepath = encryptedFilepath | ||
|
||
def isEncrypted(self): | ||
return self.encryptedFilepath is not None | ||
|
||
def getFilepath(self): | ||
return self.encryptedFilepath or self.filepath | ||
|
||
def getOriginalFilepath(self): | ||
return self.filepath | ||
|
||
def set(self, key, val): | ||
self.attributes[key] = val | ||
|
||
def get(self, key, default = None): | ||
if key in self.attributes: | ||
return self.attributes[key] | ||
|
||
return default | ||
|
||
def getOrSet(self, key, func): | ||
if not self.get(key): | ||
self.set(key, func()) | ||
|
||
def build(self, url = None, ip = None): | ||
if url: | ||
self.set("url", url) | ||
if ip: | ||
self.set("ip", ip) | ||
return self.cls.fromBuilder(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.