test_z85.py revision 781d71db
1# -*- coding: utf8 -*-
2"""Test Z85 encoding
3
4confirm values and roundtrip with test values from the reference implementation.
5"""
6
7# Copyright (C) PyZMQ Developers
8# Distributed under the terms of the Modified BSD License.
9
10from unittest import TestCase
11from zmq.utils import z85
12
13
14class TestZ85(TestCase):
15
16    def test_client_public(self):
17        client_public = \
18            b"\xBB\x88\x47\x1D\x65\xE2\x65\x9B" \
19            b"\x30\xC5\x5A\x53\x21\xCE\xBB\x5A" \
20            b"\xAB\x2B\x70\xA3\x98\x64\x5C\x26" \
21            b"\xDC\xA2\xB2\xFC\xB4\x3F\xC5\x18"
22        encoded = z85.encode(client_public)
23
24        self.assertEqual(encoded, b"Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID")
25        decoded = z85.decode(encoded)
26        self.assertEqual(decoded, client_public)
27
28    def test_client_secret(self):
29        client_secret = \
30            b"\x7B\xB8\x64\xB4\x89\xAF\xA3\x67" \
31            b"\x1F\xBE\x69\x10\x1F\x94\xB3\x89" \
32            b"\x72\xF2\x48\x16\xDF\xB0\x1B\x51" \
33            b"\x65\x6B\x3F\xEC\x8D\xFD\x08\x88"
34        encoded = z85.encode(client_secret)
35
36        self.assertEqual(encoded, b"D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs")
37        decoded = z85.decode(encoded)
38        self.assertEqual(decoded, client_secret)
39
40    def test_server_public(self):
41        server_public = \
42            b"\x54\xFC\xBA\x24\xE9\x32\x49\x96" \
43            b"\x93\x16\xFB\x61\x7C\x87\x2B\xB0" \
44            b"\xC1\xD1\xFF\x14\x80\x04\x27\xC5" \
45            b"\x94\xCB\xFA\xCF\x1B\xC2\xD6\x52"
46        encoded = z85.encode(server_public)
47
48        self.assertEqual(encoded, b"rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7")
49        decoded = z85.decode(encoded)
50        self.assertEqual(decoded, server_public)
51
52    def test_server_secret(self):
53        server_secret = \
54            b"\x8E\x0B\xDD\x69\x76\x28\xB9\x1D" \
55            b"\x8F\x24\x55\x87\xEE\x95\xC5\xB0" \
56            b"\x4D\x48\x96\x3F\x79\x25\x98\x77" \
57            b"\xB4\x9C\xD9\x06\x3A\xEA\xD3\xB7"
58        encoded = z85.encode(server_secret)
59
60        self.assertEqual(encoded, b"JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6")
61        decoded = z85.decode(encoded)
62        self.assertEqual(decoded, server_secret)
63
64