From 8c02634818982a172dc0b084b72afc1e4b1ca7ea Mon Sep 17 00:00:00 2001
From: Enji Cooper <ngie@FreeBSD.org>
Date: Tue, 21 May 2019 02:13:46 +0000
Subject: [PATCH] Squash deprecation warning related to
 array.array(..).tostring()

In version 3.2+, `array.array(..).tostring()` was renamed to
`array.array(..).tobytes()`. Conditionally call `array.array(..).tobytes()` if
the python version is 3.2+.

PR:		237403
MFC after:	1 week
---
 tests/sys/opencrypto/cryptodev.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tests/sys/opencrypto/cryptodev.py b/tests/sys/opencrypto/cryptodev.py
index 4b5ae2df54e5..3dfba66dc180 100644
--- a/tests/sys/opencrypto/cryptodev.py
+++ b/tests/sys/opencrypto/cryptodev.py
@@ -38,6 +38,7 @@
 import random
 import signal
 from struct import pack as _pack
+import sys
 import time
 
 import dpkt
@@ -151,6 +152,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):
@@ -218,9 +224,9 @@ def _doop(self, op, src, iv):
         #print('cop:', cop)
         ioctl(_cryptodev, CIOCCRYPT, str(cop))
 
-        s = s.tostring()
+        s = array_tobytes(s)
         if self._maclen is not None:
-            return s, m.tostring()
+            return s, array_tobytes(m)
 
         return s
 
@@ -255,9 +261,9 @@ def _doaead(self, op, src, aad, iv, tag=None):
 
         ioctl(_cryptodev, CIOCCRYPTAEAD, str(caead))
 
-        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)))