Пример #1
0
    def encrypt(self,
                plaintext: str,
                fingerprints: List[str],
                output: Optional[str] = None) -> str:
        # Verify the output path
        if output:
            current_app.storage.verify(output)

        # Remove any spaces from provided fingerprints GPG outputs fingerprints
        # with spaces for readability, but requires the spaces to be removed
        # when using fingerprints to specify recipients.
        fingerprints = [fpr.replace(' ', '') for fpr in fingerprints]

        if not _is_stream(plaintext):
            plaintext = _make_binary_stream(plaintext, "utf_8")

        out = self.gpg.encrypt(plaintext,
                               *fingerprints,
                               output=output,
                               always_trust=True,
                               armor=False)
        if out.ok:
            return out.data
        else:
            raise CryptoException(out.stderr)
def test_SecureTemporaryFile_is_a_STREAMLIKE_TYPE():
    assert _is_stream(SecureTemporaryFile('/tmp'))