From owner-svn-src-user@freebsd.org Tue Sep 3 14:07:25 2019 Return-Path: Delivered-To: svn-src-user@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DCB6DDDABF for ; Tue, 3 Sep 2019 14:07:25 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N80Y2bp5z4QbB; Tue, 3 Sep 2019 14:07:25 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 0D28E1B600; Tue, 3 Sep 2019 14:06:39 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 041FFD5EF; Tue, 23 Apr 2019 22:43:28 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 405148EA05; Tue, 23 Apr 2019 22:43:28 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 11439D598; Tue, 23 Apr 2019 22:43:28 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 29C98D594 for ; Tue, 23 Apr 2019 22:43:25 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D85668E9FC; Tue, 23 Apr 2019 22:43:24 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B172832E2; Tue, 23 Apr 2019 22:43:24 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3NMhO90076716; Tue, 23 Apr 2019 22:43:24 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3NMhOHB076715; Tue, 23 Apr 2019 22:43:24 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201904232243.x3NMhOHB076715@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Enji Cooper To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r346612 - user/ngie/bug-237403/tests/sys/opencrypto X-SVN-Group: user X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: user/ngie/bug-237403/tests/sys/opencrypto X-SVN-Commit-Revision: 346612 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 405148EA05 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.99)[-0.990,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.29 List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:07:26 -0000 X-Original-Date: Tue, 23 Apr 2019 22:43:24 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:07:26 -0000 Author: ngie Date: Tue Apr 23 22:43:24 2019 New Revision: 346612 URL: https://svnweb.freebsd.org/changeset/base/346612 Log: Ugh. Deal with encoding/decoding UTF-8 strings to bytes as needed I couldn't tell if the type was str in all cases, so conditionally convert it to a bytes object with py3 as needed. 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 Apr 23 22:40:39 2019 (r346611) +++ user/ngie/bug-237403/tests/sys/opencrypto/cryptodev.py Tue Apr 23 22:43:24 2019 (r346612) @@ -199,6 +199,13 @@ class Crypto: pass self._ses = None + @staticmethod + def _to_bytes(val): + if sys.version_info[0] >= 3: + if isinstance(val, str): + return val.encode("ascii") + return val + def _doop(self, op, src, iv): cop = CryptOp() cop.ses = self._ses @@ -210,7 +217,7 @@ class Crypto: if self._maclen is not None: m = array.array('B', [0] * self._maclen) cop.mac = m.buffer_info()[0] - ivbuf = array.array('B', iv) + ivbuf = array.array('B', self._to_bytes(iv)) cop.iv = ivbuf.buffer_info()[0] #print('cop:', cop) @@ -229,10 +236,12 @@ class Crypto: caead.flags = CRD_F_IV_EXPLICIT caead.flags = 0 caead.len = len(src) - s = array.array('B', src.encode("ascii")) + src = self._to_bytes(src) + s = array.array("B", src) caead.src = caead.dst = s.buffer_info()[0] caead.aadlen = len(aad) - saad = array.array('B', aad.encode("ascii")) + aad = self._to_bytes(aad) + saad = array.array('B', aad) caead.aad = saad.buffer_info()[0] if self._maclen is None: @@ -243,7 +252,8 @@ class Crypto: else: assert len(tag) == self._maclen, \ '%d != %d' % (len(tag), self._maclen) - tag = array.array('B', tag.encode("ascii")) + tag = self._to_bytes(tag) + tag = array.array('B', tag) caead.tag = tag.buffer_info()[0] @@ -251,7 +261,7 @@ class Crypto: caead.ivlen = len(iv) caead.iv = ivbuf.buffer_info()[0] - ioctl(_cryptodev, CIOCCRYPTAEAD, str(caead)) + ioctl(_cryptodev, CIOCCRYPTAEAD, self._to_bytes(str(caead))) s = s.tostring() @@ -260,7 +270,7 @@ class Crypto: def perftest(self, op, size, timeo=3): inp = array.array('B', (random.randint(0, 255) for x in xrange(size))) - out = array.array('B', inp.encode("ascii")) + out = array.array('B', self._to_bytes(inp)) # prep ioctl cop = CryptOp() @@ -268,7 +278,7 @@ class Crypto: cop.op = op cop.flags = 0 cop.len = len(inp) - s = array.array('B', inp.encode("ascii")) + s = array.array('B', self._to_bytes(inp)) cop.src = s.buffer_info()[0] cop.dst = out.buffer_info()[0] if self._maclen is not None: @@ -287,7 +297,7 @@ class Crypto: start = time.time() reps = 0 while not exit[0]: - ioctl(_cryptodev, CIOCCRYPT, str(cop)) + ioctl(_cryptodev, CIOCCRYPT, self._to_bytes(str(cop))) reps += 1 end = time.time()