@@ -127,15 +127,19 @@ def de_json(cls, data, bot):
127127 if not data :
128128 return None
129129
130- data ['secret' ] = bot .private_key .decrypt (b64decode (data .get ('secret' )), OAEP (
131- mgf = MGF1 (algorithm = SHA1 ()),
132- algorithm = SHA1 (),
133- label = None
134- ))
135- data ['data' ] = Credentials .de_json (decrypt_json (data .get ('secret' ),
136- data .get ('hash' ),
137- data .get ('data' )),
138- bot = bot )
130+ # If already decrypted
131+ if isinstance (data ['data' ], dict ):
132+ data ['data' ] = Credentials .de_json (data ['data' ], bot = bot )
133+ else :
134+ data ['secret' ] = bot .private_key .decrypt (b64decode (data .get ('secret' )), OAEP (
135+ mgf = MGF1 (algorithm = SHA1 ()),
136+ algorithm = SHA1 (),
137+ label = None
138+ ))
139+ data ['data' ] = Credentials .de_json (decrypt_json (data .get ('secret' ),
140+ data .get ('hash' ),
141+ data .get ('data' )),
142+ bot = bot )
139143
140144 return cls (bot = bot , ** data )
141145
@@ -293,6 +297,13 @@ def de_json(cls, data, bot):
293297
294298 return cls (bot = bot , ** data )
295299
300+ def to_dict (self ):
301+ data = super (SecureValue , self ).to_dict ()
302+
303+ data ['files' ] = [p .to_dict () for p in self .files ]
304+
305+ return data
306+
296307
297308class _CredentialsBase (TelegramObject ):
298309 """Base class for DataCredentials and FileCredentials."""
@@ -319,8 +330,8 @@ def de_list(cls, data, bot):
319330 return []
320331
321332 credentials = list ()
322- for credentials in data :
323- credentials .append (cls .de_json (credentials , bot = bot ))
333+ for c in data :
334+ credentials .append (cls .de_json (c , bot = bot ))
324335
325336 return credentials
326337
@@ -341,6 +352,14 @@ class DataCredentials(_CredentialsBase):
341352 def __init__ (self , data_hash , secret , ** kwargs ):
342353 super (DataCredentials , self ).__init__ (data_hash , secret , ** kwargs )
343354
355+ def to_dict (self ):
356+ data = super (DataCredentials , self ).to_dict ()
357+
358+ del data ['file_hash' ]
359+ del data ['hash' ]
360+
361+ return data
362+
344363
345364class FileCredentials (_CredentialsBase ):
346365 """
@@ -357,3 +376,11 @@ class FileCredentials(_CredentialsBase):
357376 """
358377 def __init__ (self , file_hash , secret , ** kwargs ):
359378 super (FileCredentials , self ).__init__ (file_hash , secret , ** kwargs )
379+
380+ def to_dict (self ):
381+ data = super (FileCredentials , self ).to_dict ()
382+
383+ del data ['data_hash' ]
384+ del data ['hash' ]
385+
386+ return data
0 commit comments