From aed0a42f5ff3fbe465ab196ba9b19834fa972311 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 13 Jul 2021 16:14:20 +0800 Subject: [PATCH] bugfix --- test/brotli_test.py | 13 +++++++++++++ test/dataencoder_test.py | 34 ++++++++++++++++++++++++++++++++++ test/prikey1.rsa | 27 +++++++++++++++++++++++++++ test/prikey2.rsa | 27 +++++++++++++++++++++++++++ test/time_test.py | 13 +++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 test/brotli_test.py create mode 100644 test/dataencoder_test.py create mode 100644 test/prikey1.rsa create mode 100644 test/prikey2.rsa create mode 100644 test/time_test.py diff --git a/test/brotli_test.py b/test/brotli_test.py new file mode 100644 index 0000000..14e5e59 --- /dev/null +++ b/test/brotli_test.py @@ -0,0 +1,13 @@ +import sys +from brotli import compress, decompress + +def do(fn): + with open(fn, 'rb') as f: + b = f.read() + c = compress(b) + d = decompress(c) + print(fn,'\t', + float(len(c))/float(len(b))) +fns = sys.argv[1:] +for fn in fns: + do(fn) diff --git a/test/dataencoder_test.py b/test/dataencoder_test.py new file mode 100644 index 0000000..cedba22 --- /dev/null +++ b/test/dataencoder_test.py @@ -0,0 +1,34 @@ + +from appPublic.rsa import RSA +from appPublic.dataencoder import DataEncoder + +def get_prikey(id): + prifile='prikey2.rsa' + if id=='node1': + prifile = 'prikey1.rsa' + rsa = RSA() + prikey = rsa.read_privatekey(prifile) + pubkey = rsa.create_publickey(prikey) + return pubkey + + +node1 = DataEncoder('node1', get_prikey, 'prikey1.rsa') +node2 = DataEncoder('node2', get_prikey, 'prikey2.rsa') +data1 = { + 'a':'iy34ti3y42ti23t425g4', + 'b':100, + 'c':'100', + 'd':[1124,'34t342',5445] +} +d = node1.pack('node2', data1) + +try: + data2 = node2.unpack('node1', d) + print(data1,'<===>', data2) +except: + print('ERROR:') + +print('check c', node1.pack_d[0] == node2.unpack_d[0]) +print('check d', node1.pack_d[1] == node2.unpack_d[1]) +print('check k', node1.pack_d[2] == node2.unpack_d[2], len(node1.pack_d[2])) +print('check s', node1.pack_d[3] == node2.unpack_d[3], len(node1.pack_d[3])) diff --git a/test/prikey1.rsa b/test/prikey1.rsa new file mode 100644 index 0000000..2e06dbc --- /dev/null +++ b/test/prikey1.rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEApavGY/vV0O8RE2+OaVi0slpb19hssNYREQcMrsicS7q23GlU +2NCzU95g8M3fXoOIjTwKBoUtfcvMdMzotibaTlJ+Xj7CFiSZLUYq9hRuujbUyh+a +BoeUtui33hilyksGlumdZwWaPCSrl7uYw2UoAsoFsmNWlNqXig2okfEUGBMsMjhw +GA3W5jZDa/yCGMIiZ11MfsxdIjTgkfEXsQEYfOR77Zebzfh3GaE/R6EmejJHosAQ +HDcDSzsq2ukY1GOdlap0nnINCQkg/wTHkjw/skOLk9NZhJggHnVdpaxJtWUeU9Pv +j6D3tXYopUp44A8iEXqx07uQ5GgwYfsoPVSRmwIDAQABAoIBAQCTg/9z+cKqdqSa +zMNe1EiZYtHSwPgPAZ1SrxdA7ooU+F1opzWQlUyISkPBR180diR5tdMreRxHndcg +zXAM+U17XgL9gh4pv07RPGB2mzz4/Ge+ziLE26a0s0U9Mm81UFa+u6eXGyr5kKFl +yvm8Sm81BJPMAp4OjxFOMNk/kg0VXVXwtpJOxSKBhiG/DMK3k/Cp4W82rj+/soYk +dQqYAAHvMvYIBRcrwRlhEjhnyyK/OycUxBb3uB3JgqYhg9N3cZoQUQdcETWOSuau +4zNyCjmAUlT2RLq/2jFcy66XVLsq8b+6aczPaNGNB5oRG25l78DpdE/NpISb+Dnt +y++GxxKhAoGBANbm2Mr/eWJR1E6DhKH2CGB6++sKRq4iUwnbi/yxZnWuHYsO13zX +V8wUxNBXY3GHFn3oAfMdp4iXDMhnCOaDgSiXb7JvXO9mAzN+ErjwZSJmszdKhCbC +lupXpQ1gdzixT4tgShGtIV/Mi/xtQE3j9Ld5T7PIaVcpuR5UoA+EqOqxAoGBAMVa +sMkjO91A6NT/JYL/15eQV4gWCMJXgFpRAezdfRF56GULkkJPRfsIG/IGS9SWL03c +MTtvqyrfNNbfYeIm9VKxIyvei2TN0NZLFmon6TwJVbkMIoNHELiqXB1r1liHZ0Kk +rBM7wtqqpVP5gqzMEwQqy82pLNSB1q4/x6rmYTwLAoGBAIvYvcucZMluptJRE8ax +7NGcNsPFdCltfMw1auuOJjb+j4smpWRAXooYGdvagoQmfKSCjoI/Ef75DQB8zHX1 +rd9UbQOZJMlFgV/I8zYWejngy0931nfCuaLWVjpWRD9IY5M3nfvSxp0o5w/lqKsH +ZQDgmNVN3f8yz5zFRUPT+HiBAoGAes41ReQb41D50Vi3se2b7V9PaIo1hyFF6G2S +Ih+tLMvMNdxedc64gD4Kja8nTrDp3KxRImgZfgMI8VBtq3mMnJlHhovj96Uu97of +x4zwUICKjCyl6US2fgLccR5ichJHyiuIPCuq08DuQfP4Qah3iNdMnLxR/iaRPTrI +92qGRQMCgYEAoX8nVeH/OJ6SgjlWtu2ReG5sq4l7OlYqVamj2YXsyoRmBRGLWJ+x +ffj/TYoWxykPwZ+Uy+O7EoTz/Ia4pVpQ3dOCrMpq9pksoF7ZCPe9hh9FrY/PBOij +e5nGvNWgropXLP54WzvRvicITv3I3Oe6lF7Up3HBMmfiabEHVAWeWCY= +-----END RSA PRIVATE KEY----- diff --git a/test/prikey2.rsa b/test/prikey2.rsa new file mode 100644 index 0000000..ec1dc03 --- /dev/null +++ b/test/prikey2.rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA0Mpe2xK0ZQdehx5C/nkEbNTRxXHtVJ3oNGytwUxaLikXjfyB +kApEDRFciQLkAUPFQMKNQONLRpeWxwGLK0PD4vxOHg7BxI20JANLImzNY3p819rh +GC1CG+0kZNQt1FGx/0K5Gnm5NlLUZhjqbCif6Lo2DSXhFKj39hOgxbq/IpJhOBOp +SaE10tGS7usXqQ3Efp3xbpw5Q69w9wXW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Zk3YvZO9/XV6uUkUoGVYHQsUntSIdVHzY40wNi82ywS6LPcZtSBIiGf7 +PVMTHtHRsGh871mVLplEtLT77jBQY8IhVeacqtQnrTQPpEBu5Una15NQU7n+2r+d +yzq90wKBgQCfr3RC7mFJ2Ul5UB4PL6W/KyIAANde9FUfR5AUmVJCLCA00Bmy3eBE +ibJxnBNeGHiyA91c//TraHqiRzwm+wBxKA8Kx5b3BfZrtbAyviPflmK9BikB+ScS +CKsroe8pMMQkAnL8wyG5YyrSwmpRGu9nleIyL9Nw36cTGCg8pngmPA== +-----END RSA PRIVATE KEY----- diff --git a/test/time_test.py b/test/time_test.py new file mode 100644 index 0000000..4e05fa3 --- /dev/null +++ b/test/time_test.py @@ -0,0 +1,13 @@ +import time + +def f(timeout=2): + t1 = time.time() + t = t1 + t1 += timeout + while t1 > t: + print(t, t1) + time.sleep(1) + t = time.time() + +if __name__ == '__main__': + f()