summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-02-22 14:21:38 -0800
committerDylan Baker <dylan@pnwbakers.com>2018-03-01 10:34:56 -0800
commit6b1a6be9c2ae10ff0278390e4238b22fb906377c (patch)
tree5db45b9c63fcb6d23c87990e2d2b123bddcf4ef1 /tests
parent7805f34f55f7143e1ebfca982b0654a3ef42e1d0 (diff)
crypto: use bytes instead of str
The crypto code shouldn't use unicode strings, it should use byte strings. The problem with using unicode strings (and doing the conversion internally), is that the crypto code doesn't know what the encoding should be. We can guess but it's better to just do bytes in bytes out, and let the calling code deal with encoding and decoding.
Diffstat (limited to 'tests')
-rw-r--r--tests/crypto_test.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/tests/crypto_test.py b/tests/crypto_test.py
index b059cc82..f6c02a7e 100644
--- a/tests/crypto_test.py
+++ b/tests/crypto_test.py
@@ -111,16 +111,16 @@ class TestHashAlgorithmHelper(unittest.TestCase):
class TestDetachedSignatureFor(unittest.TestCase):
def test_valid_signature_generated(self):
- to_sign = "this is some text.\nit is more than nothing.\n"
+ to_sign = b"this is some text.\nit is more than nothing.\n"
with gpg.core.Context() as ctx:
_, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)])
- with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
+ with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(detached)
sig = f.name
self.addCleanup(os.unlink, f.name)
- with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
+ with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(to_sign)
text = f.name
self.addCleanup(os.unlink, f.name)
@@ -133,7 +133,7 @@ class TestDetachedSignatureFor(unittest.TestCase):
class TestVerifyDetached(unittest.TestCase):
def test_verify_signature_good(self):
- to_sign = "this is some text.\nIt's something\n."
+ to_sign = b"this is some text.\nIt's something\n."
with gpg.core.Context() as ctx:
_, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)])
@@ -143,8 +143,8 @@ class TestVerifyDetached(unittest.TestCase):
raise AssertionError
def test_verify_signature_bad(self):
- to_sign = "this is some text.\nIt's something\n."
- similar = "this is some text.\r\n.It's something\r\n."
+ to_sign = b"this is some text.\nIt's something\n."
+ similar = b"this is some text.\r\n.It's something\r\n."
with gpg.core.Context() as ctx:
_, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)])
@@ -362,23 +362,22 @@ class TestGetKey(unittest.TestCase):
class TestEncrypt(unittest.TestCase):
def test_encrypt(self):
- to_encrypt = "this is a string\nof data."
+ to_encrypt = b"this is a string\nof data."
encrypted = crypto.encrypt(to_encrypt, keys=[crypto.get_key(FPR)])
- with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
+ with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(encrypted)
enc_file = f.name
self.addCleanup(os.unlink, enc_file)
- dec = helper.try_decode(subprocess.check_output(
- ['gpg', '--decrypt', enc_file], stderr=DEVNULL))
+ dec = subprocess.check_output(['gpg', '--decrypt', enc_file], stderr=DEVNULL)
self.assertEqual(to_encrypt, dec)
class TestDecrypt(unittest.TestCase):
def test_decrypt(self):
- to_encrypt = "this is a string\nof data."
+ to_encrypt = b"this is a string\nof data."
encrypted = crypto.encrypt(to_encrypt, keys=[crypto.get_key(FPR)])
_, dec = crypto.decrypt_verify(encrypted)
self.assertEqual(to_encrypt, dec)