-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
44 lines (35 loc) · 1.36 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from unittest import TestCase
from formats import xor
from opgp_modification import OpenPgpMsg
class TestModifier(TestCase):
def test_xor_bytes(self):
"""
Checks if the result is correct.
Manually calculation:
aG = 97 71 = 0110 0001 0100 0111
9s = 57 115 = 0011 1001 0111 0011
---------------------------------
X4 = 88 52 = 0101 1000 0011 0100
"""
testbytes_1 = b'aG'
testbytes_2 = b'9s'
expected_res = b'X4'
actual_res = xor(testbytes_1, testbytes_2)
self.assertEqual(actual_res, expected_res)
"""
F01 = 70 48 49 = 01000110 00110000 00110001
Con = 67 111 110 = 01000011 01101111 01101110
----------------------------------------------
\x05__ = 5 95 95 = 00000101 01011111 01011111
Note: Number 5 as decimal is a control character in ASCII, hence escape is needed
"""
testbytes_3 = b'F01'
testbytes_4 = b'Con'
expected_res = b'\x05__'
actual_res = xor(testbytes_3, testbytes_4)
self.assertEqual(actual_res, expected_res)
def test_len_encoding(self):
first = 0xc5.to_bytes(1, byteorder="big")
second = 0xfb.to_bytes(1, byteorder="big")
expected_res = first + second
self.assertEqual(OpenPgpMsg.encode_len(1723), expected_res)