]> wagner.pp.ru Git - oss/ctypescrypto.git/commitdiff
Use openssl pkey to convert EC key into printable form before comparing, because...
authorVictor Wagner <vitus@wagner.pp.ru>
Tue, 21 Jun 2016 14:51:35 +0000 (17:51 +0300)
committerVictor Wagner <vitus@wagner.pp.ru>
Tue, 21 Jun 2016 14:51:35 +0000 (17:51 +0300)
tests/testec.py

index 4fbf502cf7a7f3b6c8d2d5062c6f37b8dae8efaf..c5054a52ada4e3a9730d4640a2c64bedbd3adc1f 100644 (file)
@@ -1,10 +1,22 @@
 from ctypescrypto.oid import Oid
 from ctypescrypto.ec import create
 from base64 import b16decode
+from subprocess import Popen, PIPE
 import unittest
 
+def dump_key(key):
+    """ Convert key into printable form using openssl utility
+       Used to compare keys which can be stored in different
+       format by different OpenSSL versions
+    """
+    return Popen(["openssl","pkey","-text","-noout"],stdin=PIPE,stdout=PIPE).communicate(key)[0]
 
-
+def dump_pub_key(key):
+    """ Convert key into printable form using openssl utility
+       Used to compare keys which can be stored in different
+       format by different OpenSSL versions
+    """
+    return Popen(["openssl","pkey","-text_pub","-noout"],stdin=PIPE,stdout=PIPE).communicate(key)[0]
 class TestEcCreation(unittest.TestCase):
     ec1priv="""-----BEGIN PRIVATE KEY-----
 MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgKnG6neqZvB98EEuuxnHs
@@ -22,11 +34,11 @@ cUqktWYGr/GB65Zr5Ky1z/nha2bYCb6U4hTwbJP9CRCZr5hJklXn
         key=create(Oid("secp256k1"),b16decode("2A71BA9DEA99BC1F7C104BAEC671EC7EFF8BFF969BB8D346DB4C3352A4699DC3",True))
             
         out=key.exportpriv()
-        self.assertEqual(out,self.ec1priv)
+        self.assertEqual(dump_key(out),dump_key(self.ec1priv))
 
     def test_bignum(self):
         keyval='\xff'*32
         key=create(Oid("secp256k1"),keyval)
-        self.assertEqual(key.exportpriv(),self.bigkey)
+        self.assertEqual(dump_key(key.exportpriv()),dump_key(self.bigkey))
 if __name__ == "__main__":
     unittest.main()