Пример #1
0
def document_pre_open_hook(descriptor, instance):
    if DocumentVersionSignature.objects.has_embedded_signature(instance.document):
        # If it has an embedded signature decrypt
        try:
            result = gpg.decrypt_file(descriptor, close_descriptor=False)
            # gpg return a string, turn it into a file like object
        except GPGDecryptionError:
            # At least return the original raw content
            descriptor.seek(0)
            return descriptor
        else:
            descriptor.close()
            return StringIO(result.data)
    else:
        return descriptor
Пример #2
0
 def open(self, raw=False):
     '''
     Return a file descriptor to a document version's file irrespective of
     the storage backend
     '''
     if self.signature_state and not raw:
         try:
             result = gpg.decrypt_file(self.file.storage.open(self.file.path))
             # gpg return a string, turn it into a file like object
             return StringIO(result.data)
         except GPGDecryptionError:
             # At least return the original raw content
             return self.file.storage.open(self.file.path)
     else:
         return self.file.storage.open(self.file.path)
Пример #3
0
def document_pre_open_hook(descriptor, instance):
    if DocumentVersionSignature.objects.has_embedded_signature(
            document_version=instance):
        # If it has an embedded signature, decrypt
        try:
            result = gpg.decrypt_file(descriptor, close_descriptor=False)
            # gpg return a string, turn it into a file like object
        except GPGDecryptionError:
            # At least return the original raw content
            descriptor.seek(0)
            return descriptor
        else:
            descriptor.close()
            return io.BytesIO(result.data)
    else:
        return descriptor
Пример #4
0
def document_pre_open_hook(descriptor, instance):
    if DocumentVersionSignature.objects.has_embedded_signature(instance.document):
        # If it has an embedded signature decrypt
        try:
            result = gpg.decrypt_file(descriptor, close_descriptor=False)
            # gpg return a string, turn it into a file like object
        except GPGDecryptionError:
            # At least return the original raw content
            descriptor.seek(0)
            return descriptor
        else:
            descriptor.close()
            return StringIO(result.data)
    else:
        # It no embedded signature pass along
        # Doing this single DB lookup avoids trying to decrypt non signed
        # files always, which could result in slow down for big non signed
        # files
        # descriptor.seek(0)
        return descriptor
Пример #5
0
def document_pre_open_hook(descriptor, instance):
    if DocumentVersionSignature.objects.has_embedded_signature(
            instance.document):
        # If it has an embedded signature decrypt
        try:
            result = gpg.decrypt_file(descriptor, close_descriptor=False)
            # gpg return a string, turn it into a file like object
        except GPGDecryptionError:
            # At least return the original raw content
            descriptor.seek(0)
            return descriptor
        else:
            descriptor.close()
            return StringIO(result.data)
    else:
        # It no embedded signature pass along
        # Doing this single DB lookup avoids trying to decrypt non signed
        # files always, which could result in slow down for big non signed
        # files
        #descriptor.seek(0)
        return descriptor