Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 May 2019 02:02:09 +0000 (UTC)
From:      Enji Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r348030 - user/ngie/bug-237403/tests/sys/opencrypto
Message-ID:  <201905210202.x4L2297K031803@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Tue May 21 02:02:09 2019
New Revision: 348030
URL: https://svnweb.freebsd.org/changeset/base/348030

Log:
  Fix remaining encoding issues with python 3
  
  * Cast all unicode strings to bytes arrays before passing them through to
    `fcntl.ioctl`, as the string width of unicode strings is different and not
    downcast to bytes when passed to `fcntl.ioctl`.
  * Use `array.array(..).tobytes()` instead of `array.array(..).tostring()` in
    python 3.2+, per the deprecation warning printed out by python 3.6 when the
    code is evaluated.

Modified:
  user/ngie/bug-237403/tests/sys/opencrypto/cryptodev.py

Modified: user/ngie/bug-237403/tests/sys/opencrypto/cryptodev.py
==============================================================================
--- user/ngie/bug-237403/tests/sys/opencrypto/cryptodev.py	Tue May 21 01:56:26 2019	(r348029)
+++ user/ngie/bug-237403/tests/sys/opencrypto/cryptodev.py	Tue May 21 02:02:09 2019	(r348030)
@@ -153,6 +153,11 @@ def _findop(crid, name):
 
     return fop.crid, name
 
+def array_tobytes(array_obj):
+    if sys.version_info[:2] >= (3, 2):
+        return array_obj.tobytes()
+    return array_obj.tostring()
+
 class Crypto:
     @staticmethod
     def findcrid(name):
@@ -224,12 +229,13 @@ class Crypto:
         ivbuf = array.array('B', self._to_bytes(iv))
         cop.iv = ivbuf.buffer_info()[0]
 
-        #print('cop:', cop)
-        ioctl(_cryptodev, CIOCCRYPT, str(cop))
+        cop_b = bytes(cop)
+        #print('cop:', cop_b)
+        ioctl(_cryptodev, CIOCCRYPT, cop_b)
 
-        s = s.tostring()
+        s = array_tobytes(s)
         if self._maclen is not None:
-            return s, m.tostring()
+            return s, array_tobytes(m)
 
         return s
 
@@ -265,11 +271,12 @@ class Crypto:
         caead.ivlen = len(iv)
         caead.iv = ivbuf.buffer_info()[0]
 
-        ioctl(_cryptodev, CIOCCRYPTAEAD, self._to_bytes(str(caead)))
+        caead_b = bytes(caead)
+        ioctl(_cryptodev, CIOCCRYPTAEAD, caead_b)
 
-        s = s.tostring()
+        s = array_tobytes(s)
 
-        return s, tag.tostring()
+        return s, array_tobytes(tag)
 
     def perftest(self, op, size, timeo=3):
         inp = array.array('B', (random.randint(0, 255) for x in range(size)))
@@ -299,8 +306,9 @@ class Crypto:
 
         start = time.time()
         reps = 0
+        cop_b = bytes(cop)
         while not exit[0]:
-            ioctl(_cryptodev, CIOCCRYPT, self._to_bytes(str(cop)))
+            ioctl(_cryptodev, CIOCCRYPT, cop_b)
             reps += 1
 
         end = time.time()



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905210202.x4L2297K031803>