mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-10-01 03:15:44 -04:00
Fixed identity saving.
This commit is contained in:
parent
17dbfe6401
commit
972fcdee22
@ -191,6 +191,24 @@ class Identity:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def to_file(self, path):
|
||||||
|
"""
|
||||||
|
Saves the identity to a file. This will write the private key to disk,
|
||||||
|
and anyone with access to this file will be able to decrypt all
|
||||||
|
communication for the identity. Be very careful with this method.
|
||||||
|
|
||||||
|
:param path: The full path specifying where to save the identity.
|
||||||
|
:returns: True if the file was saved, otherwise False.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(path, "wb") as key_file:
|
||||||
|
key_file.write(self.get_private_key())
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while saving identity to "+str(path), RNS.LOG_ERROR)
|
||||||
|
RNS.log("The contained exception was: "+str(e))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_bytes(prv_bytes):
|
def from_bytes(prv_bytes):
|
||||||
"""
|
"""
|
||||||
@ -325,24 +343,6 @@ class Identity:
|
|||||||
self.hash = Identity.truncated_hash(self.get_public_key())
|
self.hash = Identity.truncated_hash(self.get_public_key())
|
||||||
self.hexhash = self.hash.hex()
|
self.hexhash = self.hash.hex()
|
||||||
|
|
||||||
def to_file(self, path):
|
|
||||||
"""
|
|
||||||
Saves the identity to a file. This will write the private key to disk,
|
|
||||||
and anyone with access to this file will be able to decrypt all
|
|
||||||
communication for the identity. Be very careful with this method.
|
|
||||||
|
|
||||||
:param path: The full path specifying where to save the identity.
|
|
||||||
:returns: True if the file was saved, otherwise False.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
with open(path, "wb") as key_file:
|
|
||||||
key_file.write(self.get_public_key())
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
RNS.log("Error while saving identity to "+str(path), RNS.LOG_ERROR)
|
|
||||||
RNS.log("The contained exception was: "+str(e))
|
|
||||||
|
|
||||||
def load(self, path):
|
def load(self, path):
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as key_file:
|
with open(path, "rb") as key_file:
|
||||||
|
Loading…
Reference in New Issue
Block a user