Beispiel #1
0
 def check_sign(public_key, data, signature):
     '''
         Check the signature of a python data structure with a public key
         Data is converted to an array of bytes with Serialization
         Return True if the signature is valid
     '''
     byte_data = bytes(Serialize.to_bytes(data))
     return CryptUtil.check_sign_bytes(public_key, byte_data, signature)
Beispiel #2
0
 def _read_index():
     if os.path.isfile(FileManager.index_file):
         FileManager.local_index = Serialize.from_bytes(
             FileManager._raw_file_read(FileManager.index_file))
     else:
         FileManager.local_index = {
             "version": FileManager.VERSION,
             "file_list": {}
         }
Beispiel #3
0
    def sign(private_key, data):
        '''
            Sign a python data structure with a private key
            Data is converted to an array of bytes with Serialization
            Return an array of bytes
        '''

        # Serialize return a byte array
        # Must be converted to bytes for hashing
        byte_data = bytes(Serialize.to_bytes(data))
        return CryptUtil.sign_bytes(private_key, byte_data)
Beispiel #4
0
    def from_bytes(self, complete_message):
        result = Serialize.from_bytes(complete_message)

        # None means deserialization did not work correctly
        if result is not None:
            try:
                self.version, self.username, self.network_path, self.command, self.content = result

                # ignore messages without the correct version number and correct types
                if self.version != NetworkMessage.MESSAGE_VERSION or type(self.username) is not str \
                  or type(self.network_path) is not str or type(self.command) is not str:
                    self.username = None
                    self.network_path = None
                    self.command = None
                    self.content = None
            except:
                # could not parse the result in the correct list of variables
                pass
Beispiel #5
0
 def to_bytes(self):
     return Serialize.to_bytes([
         self.version, self.username, self.network_path, self.command,
         self.content
     ])
Beispiel #6
0
    def file_write(network_path, new_content):
        FileManager._update_index_file_write(network_path)

        filename = FileManager.get_file_name(network_path)
        FileManager._raw_file_write(filename, Serialize.to_bytes(new_content))
Beispiel #7
0
 def file_read(network_path):
     filename = FileManager.get_file_name(network_path)
     return Serialize.from_bytes(FileManager._raw_file_read(filename))
Beispiel #8
0
 def _write_index():
     FileManager._raw_file_write(
         FileManager.index_file,
         Serialize.to_bytes(FileManager.local_index))