How to use test_sign method in localstack

Best Python code snippet using localstack_python

test_gostsignature.py

Source:test_gostsignature.py Github

copy

Full Screen

1import unittest2import os3import pytest4from unittest import mock5import gostcrypto6from gostcrypto.utils import bytearray_to_int7from gostcrypto.utils import int_to_bytearray8from gostcrypto.gostsignature import GOSTSignatureError9TEST_CURVE = {10 'id-tc26-gost-3410-2012-256-paramSetTest':dict(11 p=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000000000000000000000000000000000431')),12 a=0x07,13 b=bytearray_to_int(bytearray.fromhex('5fbff498aa938ce739b8e022fbafef40563f6e6a3472fc2a514c0ce9dae23b7e')),14 m=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),15 q=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),16 x=0x02,17 y=bytearray_to_int(bytearray.fromhex('08e2a8a0e65147d4bd6316030e16d19c85c97f0a9ca267122b96abbcea7e8fc8'))18 ),19 'id-tc26-gost-3410-2012-256-paramSetTest_raises_1':dict(20 p=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),21 a=0x07,22 b=bytearray_to_int(bytearray.fromhex('5fbff498aa938ce739b8e022fbafef40563f6e6a3472fc2a514c0ce9dae23b7e')),23 m=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),24 q=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),25 x=0x02,26 y=bytearray_to_int(bytearray.fromhex('08e2a8a0e65147d4bd6316030e16d19c85c97f0a9ca267122b96abbcea7e8fc8'))27 ),28 'id-tc26-gost-3410-2012-256-paramSetTest_raises_2':dict(29 p=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000000000000000000000000000000000431')),30 a=0x07,31 b=bytearray_to_int(bytearray.fromhex('5fbff498aa938ce739b8e022fbafef40563f6e6a3472fc2a514c0ce9dae23b7e')),32 m=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),33 q=0x41,34 x=0x02,35 y=bytearray_to_int(bytearray.fromhex('08e2a8a0e65147d4bd6316030e16d19c85c97f0a9ca267122b96abbcea7e8fc8'))36 ),37 'id-tc26-gost-3410-2012-256-paramSetTest_raises_3':dict(38 p=0x02,39 a=0x07,40 b=bytearray_to_int(bytearray.fromhex('5fbff498aa938ce739b8e022fbafef40563f6e6a3472fc2a514c0ce9dae23b7e')),41 m=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),42 q=0x70,43 x=0x02,44 y=bytearray_to_int(bytearray.fromhex('08e2a8a0e65147d4bd6316030e16d19c85c97f0a9ca267122b96abbcea7e8fc8'))45 ),46 'id-tc26-gost-3410-2012-256-paramSetTest_raises_6':dict(47 p=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000000000000000000000000000000000431')),48 a=0x07,49 b=0x0e,50 m=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),51 q=bytearray_to_int(bytearray.fromhex('8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3')),52 x=0x02,53 y=bytearray_to_int(bytearray.fromhex('08e2a8a0e65147d4bd6316030e16d19c85c97f0a9ca267122b96abbcea7e8fc8'))54 ),55 'id-tc26-gost-3410-2012-512-paramSetTest':dict(56 p=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15df1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373')),57 a=0x07,58 b=bytearray_to_int(bytearray.fromhex('1cff0806a31116da29d8cfa54e57eb748bc5f377e49400fdd788b649eca1ac4361834013b2ad7322480a89ca58e0cf74bc9e540c2add6897fad0a3084f302adc')),59 m=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15da82f2d7ecb1dbac719905c5eecc423f1d86e25edbe23c595d644aaf187e6e6df')),60 q=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15da82f2d7ecb1dbac719905c5eecc423f1d86e25edbe23c595d644aaf187e6e6df')),61 x=bytearray_to_int(bytearray.fromhex('24d19cc64572ee30f396bf6ebbfd7a6c5213b3b3d7057cc825f91093a68cd762fd60611262cd838dc6b60aa7eee804e28bc849977fac33b4b530f1b120248a9a')),62 y=bytearray_to_int(bytearray.fromhex('2bb312a43bd2ce6e0d020613c857acddcfbf061e91e5f2c3f32447c259f39b2c83ab156d77f1496bf7eb3351e1ee4e43dc1a18b91b24640b6dbb92cb1add371e'))63 ),64 'id-tc26-gost-3410-2012-512-paramSetTest_raises_4':dict(65 p=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15df1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373')),66 a=0x07,67 b=bytearray_to_int(bytearray.fromhex('1cff0806a31116da29d8cfa54e57eb748bc5f377e49400fdd788b649eca1ac4361834013b2ad7322480a89ca58e0cf74bc9e540c2add6897fad0a3084f302adc')),68 m=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15da82f2d7ecb1dbac719905c5eecc423f1d86e25edbe23c595d644aaf187e6e6df')),69 q=0x02,70 x=bytearray_to_int(bytearray.fromhex('24d19cc64572ee30f396bf6ebbfd7a6c5213b3b3d7057cc825f91093a68cd762fd60611262cd838dc6b60aa7eee804e28bc849977fac33b4b530f1b120248a9a')),71 y=bytearray_to_int(bytearray.fromhex('2bb312a43bd2ce6e0d020613c857acddcfbf061e91e5f2c3f32447c259f39b2c83ab156d77f1496bf7eb3351e1ee4e43dc1a18b91b24640b6dbb92cb1add371e'))72 ),73 'id-tc26-gost-3410-2012-512-paramSetTest_raises_5':dict(74 p=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15df1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373')),75 a=0x07,76 b=bytearray_to_int(bytearray.fromhex('1cff0806a31116da29d8cfa54e57eb748bc5f377e49400fdd788b649eca1ac4361834013b2ad7322480a89ca58e0cf74bc9e540c2add6897fad0a3084f302adc')),77 m=bytearray_to_int(bytearray.fromhex('4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15da82f2d7ecb1dbac719905c5eecc423f1d86e25edbe23c595d644aaf187e6e6df')),78 q=0x41,79 x=bytearray_to_int(bytearray.fromhex('24d19cc64572ee30f396bf6ebbfd7a6c5213b3b3d7057cc825f91093a68cd762fd60611262cd838dc6b60aa7eee804e28bc849977fac33b4b530f1b120248a9a')),80 y=bytearray_to_int(bytearray.fromhex('2bb312a43bd2ce6e0d020613c857acddcfbf061e91e5f2c3f32447c259f39b2c83ab156d77f1496bf7eb3351e1ee4e43dc1a18b91b24640b6dbb92cb1add371e'))81 ),82 'id-tc26-gost-3410-2012-256-paramSetTestEdvardsA': dict(83 p=bytearray_to_int(bytearray([84 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,85 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,86 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,87 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd,88 0x9789 ])),90 e=0x01,91 d=bytearray_to_int(bytearray([92 0x06, 0x05, 0xf6, 0xb7, 0xc1, 0x83, 0xfa, 0x81,93 0x57, 0x8b, 0xc3, 0x9c, 0xfa, 0xd5, 0x18, 0x13,94 0x2b, 0x9d, 0xf6, 0x28, 0x97, 0x00, 0x9a, 0xf7,95 0xe5, 0x22, 0xc3, 0x2d, 0x6d, 0xc7, 0xbf, 0xfb96 ])),97 m=bytearray_to_int(bytearray([98 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,100 0x00, 0x3f, 0x63, 0x37, 0x7f, 0x21, 0xed, 0x98,101 0xd7, 0x04, 0x56, 0xbd, 0x55, 0xb0, 0xd8, 0x31,102 0x9c103 ])),104 q=bytearray_to_int(bytearray([105 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,107 0x0f, 0xd8, 0xcd, 0xdf, 0xc8, 0x7b, 0x66, 0x35,108 0xc1, 0x15, 0xaf, 0x55, 0x6c, 0x36, 0x0c, 0x67109 ])),110 u=0x0d,111 v=bytearray_to_int(bytearray([112 0x60, 0xca, 0x1e, 0x32, 0xaa, 0x47, 0x5b, 0x34,113 0x84, 0x88, 0xc3, 0x8f, 0xab, 0x07, 0x64, 0x9c,114 0xe7, 0xef, 0x8d, 0xbe, 0x87, 0xf2, 0x2e, 0x81,115 0xf9, 0x2b, 0x25, 0x92, 0xdb, 0xa3, 0x00, 0xe7116 ])),117 ),118 'id-tc26-gost-3410-2012-256-paramSetTestEdvardsB': dict(119 p=bytearray_to_int(bytearray([120 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,121 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,122 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,123 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd,124 0x97125 ])),126 a=bytearray_to_int(bytearray([127 0x00, 0xc2, 0x17, 0x3f, 0x15, 0x13, 0x98, 0x16,128 0x73, 0xaf, 0x48, 0x92, 0xc2, 0x30, 0x35, 0xa2,129 0x7c, 0xe2, 0x5e, 0x20, 0x13, 0xbf, 0x95, 0xaa,130 0x33, 0xb2, 0x2c, 0x65, 0x6f, 0x27, 0x7e, 0x73,131 0x35132 ])),133 b=bytearray_to_int(bytearray([134 0x29, 0x5f, 0x9b, 0xae, 0x74, 0x28, 0xed, 0x9c,135 0xcc, 0x20, 0xe7, 0xc3, 0x59, 0xa9, 0xd4, 0x1a,136 0x22, 0xfc, 0xcd, 0x91, 0x08, 0xe1, 0x7b, 0xf7,137 0xba, 0x93, 0x37, 0xa6, 0xf8, 0xae, 0x95, 0x13138 ])),139 e=0x01,140 d=bytearray_to_int(bytearray([141 0x06, 0x05, 0xf6, 0xb7, 0xc1, 0x83, 0xfa, 0x81,142 0x57, 0x8b, 0xc3, 0x9c, 0xfa, 0xd5, 0x18, 0x13,143 0x2b, 0x9d, 0xf6, 0x28, 0x97, 0x00, 0x9a, 0xf7,144 0xe5, 0x22, 0xc3, 0x2d, 0x6d, 0xc7, 0xbf, 0xfb145 ])),146 m=bytearray_to_int(bytearray([147 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,149 0x00, 0x3f, 0x63, 0x37, 0x7f, 0x21, 0xed, 0x98,150 0xd7, 0x04, 0x56, 0xbd, 0x55, 0xb0, 0xd8, 0x31,151 0x9c152 ])),153 q=bytearray_to_int(bytearray([154 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,156 0x0f, 0xd8, 0xcd, 0xdf, 0xc8, 0x7b, 0x66, 0x35,157 0xc1, 0x15, 0xaf, 0x55, 0x6c, 0x36, 0x0c, 0x67158 ])),159 x=bytearray_to_int(bytearray([160 0x00, 0x91, 0xe3, 0x84, 0x43, 0xa5, 0xe8, 0x2c,161 0x0d, 0x88, 0x09, 0x23, 0x42, 0x57, 0x12, 0xb2,162 0xbb, 0x65, 0x8b, 0x91, 0x96, 0x93, 0x2e, 0x02,163 0xc7, 0x8b, 0x25, 0x82, 0xfe, 0x74, 0x2d, 0xaa,164 0x28165 ])),166 y=bytearray_to_int(bytearray([167 0x32, 0x87, 0x94, 0x23, 0xab, 0x1a, 0x03, 0x75,168 0x89, 0x57, 0x86, 0xc4, 0xbb, 0x46, 0xe9, 0x56,169 0x5f, 0xde, 0x0b, 0x53, 0x44, 0x76, 0x67, 0x40,170 0xaf, 0x26, 0x8a, 0xdb, 0x32, 0x32, 0x2e, 0x5c171 ])),172 u=0x0d,173 v=bytearray_to_int(bytearray([174 0x60, 0xca, 0x1e, 0x32, 0xaa, 0x47, 0x5b, 0x34,175 0x84, 0x88, 0xc3, 0x8f, 0xab, 0x07, 0x64, 0x9c,176 0xe7, 0xef, 0x8d, 0xbe, 0x87, 0xf2, 0x2e, 0x81,177 0xf9, 0x2b, 0x25, 0x92, 0xdb, 0xa3, 0x00, 0xe7178 ])),179 )180}181TEST_PRIVATE_KEY_256 = bytearray.fromhex('7a929ade789bb9be10ed359dd39a72c11b60961f49397eee1d19ce9891ec3b28')182TEST_DIGEST_256 = bytearray.fromhex('2dfbc1b372d89a1188c09c52e0eec61fce52032ab1022e8e67ece6672b043ee5')183TEST_RANDOM_256 = bytearray.fromhex('77105c9b20bcd3122823c8cf6fcc7b956de33814e95b7fe64fed924594dceab3')184TEST_RANDOM_256_EDVARDS = bytearray.fromhex('37105c9b20bcd3122823c8cf6fcc7b956de33814e95b7fe64fed924594dceab3')185TEST_SIGNATURE_256 = bytearray.fromhex('41aa28d2f1ab148280cd9ed56feda41974053554a42767b83ad043fd39dc049301456c64ba4642a1653c235a98a60249bcd6d3f746b631df928014f6c5bf9c40')186TEST_SIGNATURE_256_ZERO = bytearray.fromhex('00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')187TEST_PUBLIC_KEY_256 = bytearray.fromhex('7f2b49e270db6d90d8595bec458b50c58585ba1d4e9b788f6689dbd8e56fd80b26f1b489d6701dd185c8413a977b3cbbaf64d1c593d26627dffb101a87ff77da')188TEST_PRIVATE_KEY_512 = bytearray.fromhex('0ba6048aadae241ba40936d47756d7c93091a0e8514669700ee7508e508b102072e8123b2200a0563322dad2827e2714a2636b7bfd18aadfc62967821fa18dd4')189TEST_DIGEST_512 = bytearray.fromhex('3754f3cfacc9e0615c4f4a7c4d8dab531b09b6f9c170c533a71d147035b0c5917184ee536593f4414339976c647c5d5a407adedb1d560c4fc6777d2972075b8c')190TEST_RANDOM_512 = bytearray.fromhex('0359e7f4b1410feacc570456c6801496946312120b39d019d455986e364f365886748ed7a44b3e794434006011842286212273a6d14cf70ea3af71bb1ae679f1')191TEST_SIGNATURE_512 = bytearray.fromhex('2f86fa60a081091a23dd795e1e3c689ee512a3c82ee0dcc2643c78eea8fcacd35492558486b20f1c9ec197c90699850260c93bcbcd9c5c3317e19344e173ae361081b394696ffe8e6585e7a9362d26b6325f56778aadbc081c0bfbe933d52ff5823ce288e8c4f362526080df7f70ce406a6eeb1f56919cb92a9853bde73e5b4a')192TEST_PUBLIC_KEY_512 = bytearray.fromhex('115dc5bc96760c7b48598d8ab9e740d4c4a85a65be33c1815b5c320c854621dd5a515856d13314af69bc5b924c8b4ddff75c45415c1d9dd9dd33612cd530efe137c7c90cd40b0f5621dc3ac1b751cfa0e2634fa0503b3d52639f5d7fb72afd61ea199441d943ffe7f0c70a2759a3cdb84c114e1f9339fdf27f35eca93677beec')193count_urandom = 0194def os_urandom(value):195 add = bytearray([0xff, 0xff])196 global count_urandom197 count_urandom = count_urandom + 1198 if count_urandom == 1:199 return TEST_RANDOM_512 + add200 else:201 return TEST_RANDOM_512202@pytest.mark.signature203class TestMODE256(unittest.TestCase):204 def test_init_raises(self):205 with self.assertRaises(GOSTSignatureError) as context:206 test_sign = gostcrypto.gostsignature.new(None, TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest'])207 self.assertTrue('unsupported signature mode' in str(context.exception))208 def test_init_raises_0(self):209 none_curve = dict(f = 0x00, u = 0x00)210 with self.assertRaises(GOSTSignatureError) as context:211 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,212 none_curve)213 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))214 def test_init_raises_1(self):215 with self.assertRaises(GOSTSignatureError) as context:216 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,217 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest_raises_1'])218 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))219 def test_init_raises_2(self):220 with self.assertRaises(GOSTSignatureError) as context:221 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,222 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest_raises_2'])223 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest']['q'] = old_q224 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))225 def test_init_raises_3(self):226 with self.assertRaises(GOSTSignatureError) as context:227 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,228 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest_raises_3'])229 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))230 def test_init_raises_4(self):231 with self.assertRaises(GOSTSignatureError) as context:232 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,233 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest_raises_4'])234 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))235 236 def test_init_raises_5(self):237 with self.assertRaises(GOSTSignatureError) as context:238 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,239 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest_raises_5'])240 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))241 242 def test_init_raises_6(self):243 with self.assertRaises(GOSTSignatureError) as context:244 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,245 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest_raises_6'])246 self.assertTrue('invalid parameters of the elliptic curve' in str(context.exception))247 def test_sign_256(self):248 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,249 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])250 self.assertEqual(test_sign.sign(TEST_PRIVATE_KEY_256, TEST_DIGEST_256, TEST_RANDOM_256),251 TEST_SIGNATURE_256)252 def test_sign_edvards_a(self):253 signature = bytearray.fromhex('33dd7cffb7abd971669508fe0d4a1248c3a656108292ed18280cc02d7f0bd3f72e3746c7f6a77491c0edc7b2493f36d007b88c411761c1b303ba851947113166')254 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,255 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTestEdvardsA'])256 self.assertEqual(test_sign.sign(TEST_PRIVATE_KEY_256, TEST_DIGEST_256, TEST_RANDOM_256_EDVARDS),257 signature)258 def test_sign_edvards_b(self):259 signature = bytearray.fromhex('33dd7cffb7abd971669508fe0d4a1248c3a656108292ed18280cc02d7f0bd3f72e3746c7f6a77491c0edc7b2493f36d007b88c411761c1b303ba851947113166')260 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,261 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTestEdvardsB'])262 self.assertEqual(test_sign.sign(TEST_PRIVATE_KEY_256, TEST_DIGEST_256, TEST_RANDOM_256_EDVARDS),263 signature)264 def test_sign_raises(self):265 #Test 'invalid private key value'266 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,267 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])268 with self.assertRaises(GOSTSignatureError) as context:269 self.assertEqual(test_sign.sign('test_private_key', TEST_DIGEST_256, TEST_RANDOM_256),270 TEST_SIGNATURE_256)271 self.assertTrue('invalid private key value' in str(context.exception))272 #Test 'invalid digest value'273 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,274 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])275 with self.assertRaises(GOSTSignatureError) as context:276 self.assertEqual(test_sign.sign(TEST_PRIVATE_KEY_256, 'test_digest', TEST_RANDOM_256),277 TEST_SIGNATURE_256)278 self.assertTrue('invalid digest value' in str(context.exception))279 #Test 'invalid random value' (not a byte object)280 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,281 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])282 with self.assertRaises(GOSTSignatureError) as context:283 test_sign.sign(TEST_PRIVATE_KEY_256, TEST_DIGEST_256, 'test_random')284 self.assertTrue('invalid random value' in str(context.exception))285 #Test 'invalid random value' (random value >= 'q')286 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,287 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])288 with self.assertRaises(GOSTSignatureError) as context:289 test_sign.sign(TEST_PRIVATE_KEY_256, TEST_DIGEST_256, TEST_RANDOM_512)290 self.assertTrue('invalid random value' in str(context.exception))291 def test_verify_256(self):292 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,293 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])294 self.assertEqual(test_sign.verify(TEST_PUBLIC_KEY_256, TEST_DIGEST_256,295 TEST_SIGNATURE_256), True)296 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,297 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])298 self.assertEqual(test_sign.verify(TEST_PUBLIC_KEY_256, TEST_DIGEST_256,299 TEST_SIGNATURE_256_ZERO), False)300 def test_verify_raises(self):301 #Test 'invalid public key value'302 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,303 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])304 with self.assertRaises(GOSTSignatureError) as context:305 test_sign.verify('test_public_key', TEST_DIGEST_256, TEST_SIGNATURE_256)306 self.assertTrue('invalid public key value' in str(context.exception))307 #Test 'invalid signature value'308 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,309 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])310 with self.assertRaises(GOSTSignatureError) as context:311 test_sign.verify(TEST_PUBLIC_KEY_256, TEST_DIGEST_256, 'test_signature')312 self.assertTrue('invalid signature value' in str(context.exception))313 #Test 'invalid digest value'314 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,315 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])316 with self.assertRaises(GOSTSignatureError) as context:317 test_sign.verify(TEST_PUBLIC_KEY_256, 'test_digest', TEST_SIGNATURE_256)318 self.assertTrue('invalid digest value' in str(context.exception))319 def test_public_key_generate_256(self):320 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,321 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])322 self.assertEqual(test_sign.public_key_generate(TEST_PRIVATE_KEY_256), TEST_PUBLIC_KEY_256)323 def test_public_key_generate_raises(self):324 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,325 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])326 with self.assertRaises(GOSTSignatureError) as context:327 test_sign.public_key_generate('test_private_key')328 self.assertTrue('invalid private key' in str(context.exception))329class TestMODE512(unittest.TestCase):330 def test_sign_512(self):331 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,332 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest'])333 self.assertEqual(test_sign.sign(TEST_PRIVATE_KEY_512, TEST_DIGEST_512, TEST_RANDOM_512),334 TEST_SIGNATURE_512)335 def test_verify_512(self):336 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,337 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest'])338 self.assertEqual(test_sign.verify(TEST_PUBLIC_KEY_512, TEST_DIGEST_512,339 TEST_SIGNATURE_512), True)340 def test_public_key_generate_512(self):341 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,342 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest'])343 self.assertEqual(test_sign.public_key_generate(TEST_PRIVATE_KEY_512), TEST_PUBLIC_KEY_512)344 def test_sign_urandom(self):345 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,346 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest'])347 with mock.patch('os.urandom', os_urandom):348 test_result = test_sign.sign(TEST_PRIVATE_KEY_512, TEST_DIGEST_512)349 self.assertEqual(test_result, TEST_SIGNATURE_512)350 def test_oid(self):351 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_256,352 TEST_CURVE['id-tc26-gost-3410-2012-256-paramSetTest'])353 self.assertEqual(test_sign.oid.__str__(), '1.2.643.7.1.1.1.1')354 self.assertEqual(test_sign.oid.digit, tuple([1, 2, 643, 7, 1, 1, 1, 1]))355 self.assertEqual(test_sign.oid.name, 'id-tc26-gost3410-12-256')356 self.assertEqual(test_sign.oid.octet, bytearray([0x06, 0x08, 0x2a, 0x85, 0x03, 0x07, 0x01, 0x01, 0x01, 0x01,]))357 test_sign = gostcrypto.gostsignature.new(gostcrypto.gostsignature.MODE_512,358 TEST_CURVE['id-tc26-gost-3410-2012-512-paramSetTest'])359 self.assertEqual(test_sign.oid.__str__(), '1.2.643.7.1.1.1.2')360 self.assertEqual(test_sign.oid.digit, tuple([1, 2, 643, 7, 1, 1, 1, 2]))361 self.assertEqual(test_sign.oid.name, 'id-tc26-gost3410-12-512')...

Full Screen

Full Screen

test_signmessage.py

Source:test_signmessage.py Github

copy

Full Screen

1from binascii import hexlify, unhexlify2import cbor23import pytest4from cose.messages.cosemessage import CoseMessage5from cose.messages.signmessage import SignMessage6from tests.conftest import _setup_signers7def test_sign_encoding(test_sign):8 test_input = test_sign['input']9 test_output = test_sign['output']10 signers = _setup_signers(test_input['signers'])11 msg = SignMessage(12 phdr=test_input['protected'],13 uhdr=test_input['unprotected'],14 payload=test_input['plaintext'],15 signers=signers)16 assert msg.phdr == test_input['protected']17 assert msg.uhdr == test_input['unprotected']18 for s, s_output in zip(msg.signers, test_output['signers']):19 assert hexlify(s._sig_structure) == hexlify(s_output['structure'])20 if 'signature' in s_output:21 assert s.compute_signature() == s_output['signature']22 # remove signature for probabilistic behavior23 do_tag = test_sign['cbor_tag']24 msg_dec = cbor2.loads(msg.encode(tag=do_tag))25 test_dec = test_output['result']26 if 'signature' not in s_output:27 msg = msg_dec.value if do_tag else msg_dec28 for signer in msg[3]:29 signer[2] = b''30 msg = test_dec.value if do_tag else test_dec31 for signer in msg[3]:32 signer[2] = b''33 assert msg_dec == test_dec34@pytest.mark.xfail(reason="Message not tagged", raises=AttributeError)35def test_sign1_decoding(test_sign):36 test_input = test_sign['input']37 test_output = test_sign['output']38 msg = CoseMessage.decode(cbor2.dumps(test_output['result']))39 for s, s_input, s_output in zip(msg.signers, test_input['signers'], test_output['signers']):40 s.external_aad = unhexlify(s_input['external_aad'])41 s.key = s_input['signing_key']42 assert hexlify(s._sig_structure) == hexlify(s_output['structure'])...

Full Screen

Full Screen

test_sign.py

Source:test_sign.py Github

copy

Full Screen

2class test_sign:3 def init(self):4 for dtype in util.TYPES.ALL_SIGNED:5 yield "a = M.arange(-10, 0, 1, dtype=%s); " % dtype6 def test_sign(self, cmd):7 return cmd + "res = M.sign(a)"8class test_csign:9 def init(self):10 for dtype in util.TYPES.ALL_SIGNED:11 yield "a = M.arange(10, 0, 1, dtype=%s); " % dtype12 def test_sign(self, cmd):13 return cmd + "res = M.sign(a)"14class test_csign_neg:15 def init(self):16 for dtype in util.TYPES.ALL_SIGNED:17 yield "a = M.arange(-10, 0, 1, dtype=%s);" % dtype18 def test_sign(self, cmd):19 return cmd + "res = M.sign(a)"20class test_csign_zero:21 def init(self):22 for dtype in util.TYPES.ALL_SIGNED:23 yield "a = M.zeros(10, dtype=%s);" % dtype24 def test_sign(self, cmd):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful