svn commit: r346449 - user/ngie/bug-237403/tests/sys/opencrypto

Enji Cooper yaneurabeya at gmail.com
Tue Sep 3 14:07:14 UTC 2019


> On Apr 20, 2019, at 9:07 AM, Enji Cooper <ngie at FreeBSD.org> wrote:
> 
> Author: ngie
> Date: Sat Apr 20 16:07:47 2019
> New Revision: 346449
> URL: https://svnweb.freebsd.org/changeset/base/346449
> 
> Log:
>  Replace `str.{decode,encode}("hex")` with binascii.(un)?hexlify
> 
>  Encoding/decoding base_string objects as "hex" was removed in py3 and replaced
>  with other methods, one being `binascii.(un)?hexlify`.

I accidentally introduced other changes in this commit to cryptodev.py. Summary is as follows:

Py3 changed the default text encoding from ascii strings to Unicode strings, which requires converting a number of code which working previously with ascii to use byte (ascii binary, e.g., b’' prefixed) strings. In order to convert between ascii binary and unicode strings (which some of the dpkt/crypto APIs require), one must use the .decode/.encode methods, as described in the Unicode guide: https://docs.python.org/3/howto/unicode.html.

This change introduces a work-in-progress item to use .decode/.encode in cryptodev.py . It’s not 100% complete, so the tests fail when converting objects to/from str/bytes objects, like shown below.

Cheers,
-Enji

$ sudo kyua debug -k /usr/tests/sys/opencrypto/Kyuafile runtests:main 2>&1 | less
======================================================================
ERROR: test_gcm (__main__.GenTestCase.<locals>.GendCryptoTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/tests/sys/opencrypto/cryptotest.py", line 77, in test_gcm
    self.runGCM(i, 'ENCRYPT')
  File "/usr/tests/sys/opencrypto/cryptotest.py", line 126, in runGCM
    rct, rtag = c.encrypt(pt, iv, aad)
  File "/usr/tests/sys/opencrypto/cryptodev.py", line 305, in encrypt
    iv)
  File "/usr/tests/sys/opencrypto/cryptodev.py", line 232, in _doaead
    s = array.array('B', src.encode("ascii"))
AttributeError: 'bytes' object has no attribute ‘encode'
...
======================================================================
ERROR: test_gcm (__main__.GenTestCase.<locals>.GendCryptoTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/tests/sys/opencrypto/cryptotest.py", line 77, in test_gcm
    self.runGCM(i, 'ENCRYPT')
  File "/usr/tests/sys/opencrypto/cryptotest.py", line 126, in runGCM
    rct, rtag = c.encrypt(pt, iv, aad)
  File "/usr/tests/sys/opencrypto/cryptodev.py", line 305, in encrypt
    iv)
  File "/usr/tests/sys/opencrypto/cryptodev.py", line 232, in _doaead
    s = array.array('B', src.encode("ascii"))
AttributeError: 'bytes' object has no attribute 'encode'




More information about the svn-src-user mailing list