Here, I generate a key pair for the transaction then I deepcopy it later, which generates the pickling error:
from Crypto.PublicKey import RSA
import random
import sys
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_v1_5
import copy
class Transaction():
def __init__(self,
id=0,requester=0,requesterPK =0, pubkey=0, privkey=0,data=0):
self.id = id #the uinque id or the hash of the transaction
self.requester = requester
self.requesterPK = requesterPK #Requester primary key
self.pubkey = pubkey
self.privkey = privkey
self.data = data
self.verified=False
def create_transactions():# Tx sender changes as the Tx propagates while Tx requester stays same
Tn = 5
simTime = 5
Psize= int(Tn * simTime) # Tx rate times simTime
for i in range(Psize):
# assign values for transactions' attributes. You can ignore some attributes if not of an interest, and the default values will then be used
tx= Transaction()
tx.id= random.randrange(100000000000)
tx.data = f"{tx.id}file.txt"
file1 = open(tx.data, "w")
s= str(tx.id)
file1.write(s)
tx.requesterPK = RSA.generate(1024)
tx.privkey = f"{tx.id}Privkey.out"
f = open(tx.privkey,"wb")
f.write(tx.requesterPK.exportKey('PEM'))
f.close()
tx.requesterPubkey = tx.requesterPK.publickey()
tx.pubkey = f"{tx.id}Pubkey.out"
f = open(tx.pubkey, "wb")
f.write(tx.requesterPubkey.exportKey('OpenSSH'))
f.close()
tx.transaction_prop()
def transaction_prop(self):
t= copy.deepcopy(self)
Transaction.create_transactions()
the output is:
Traceback (most recent call last):
File "trial2.py", line 47, in <module>
Transaction.create_transactions()
File "trial2.py", line 41, in create_transactions
tx.transaction_prop()
File "trial2.py", line 44, in transaction_prop
t= copy.deepcopy(self)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/copy.py", line 161, in deepcopy
rv = reductor(4)
File "/Users/riham/Library/Python/3.8/lib/python/site-packages/Crypto/PublicKey/RSA.py", line 210, in __getstate__
raise PicklingError
_pickle.PicklingError