2015-08-20 17:27:15 +02:00
|
|
|
import binascii
|
2017-12-29 19:55:35 +01:00
|
|
|
from twisted.internet import defer
|
2015-08-20 17:27:15 +02:00
|
|
|
from lbrynet.cryptstream.CryptBlob import StreamBlobDecryptor
|
|
|
|
|
|
|
|
|
|
|
|
class CryptBlobHandler(object):
|
2018-07-03 06:51:25 +02:00
|
|
|
#implements(IBlobHandler)
|
2015-08-20 17:27:15 +02:00
|
|
|
|
|
|
|
def __init__(self, key, write_func):
|
|
|
|
self.key = key
|
|
|
|
self.write_func = write_func
|
|
|
|
|
|
|
|
######## IBlobHandler #########
|
|
|
|
|
|
|
|
def handle_blob(self, blob, blob_info):
|
2017-12-29 19:55:35 +01:00
|
|
|
try:
|
|
|
|
blob_decryptor = StreamBlobDecryptor(blob, self.key, binascii.unhexlify(blob_info.iv),
|
|
|
|
blob_info.length)
|
|
|
|
except ValueError as err:
|
|
|
|
return defer.fail(err)
|
2015-08-20 17:27:15 +02:00
|
|
|
d = blob_decryptor.decrypt(self.write_func)
|
2016-11-30 21:20:45 +01:00
|
|
|
return d
|