Skip to content

Instantly share code, notes, and snippets.

@ifundef
Last active August 29, 2015 14:01
Show Gist options
  • Save ifundef/d3af7593f7d6db5e82b4 to your computer and use it in GitHub Desktop.
Save ifundef/d3af7593f7d6db5e82b4 to your computer and use it in GitHub Desktop.
test_dhcrypto.py traceback (python2: struct.unpack() can't operate on bytearray)
$ PYTHONPATH=. python2 tests/test_dhcrypto.py
Traceback (most recent call last):
File "tests/test_dhcrypto.py", line 8, in <module>
from secretstorage.dhcrypto import long_to_bytes, bytes_to_long
File "/tmp/secretstorage/secretstorage/__init__.py", line 14, in <module>
from secretstorage.collection import Collection, create_collection, \
File "/tmp/secretstorage/secretstorage/collection.py", line 21, in <module>
from secretstorage.item import Item
File "/tmp/secretstorage/secretstorage/item.py", line 15, in <module>
from secretstorage.util import InterfaceWrapper, bus_get_object, \
File "/tmp/secretstorage/secretstorage/util.py", line 13, in <module>
from secretstorage.dhcrypto import Session
File "/tmp/secretstorage/secretstorage/dhcrypto.py", line 42, in <module>
DH_PRIME_1024 = bytes_to_long(DH_PRIME_1024_BYTES)
File "/tmp/secretstorage/secretstorage/dhcrypto.py", line 33, in <lambda>
bytes_to_long = lambda b: _to_long(bytearray(b))
File "/tmp/python2/local/lib/python2.7/site-packages/Crypto/Util/number.py", line 431, in bytes_to_long
acc = (acc << 32) + unpack('>I', s[i:i+4])[0]
struct.error: unpack requires a string argument of length 4
$ git log -n1
commit eb6046236de59313f50232c2a4c94f6a94aaff4e
Author: Dmitry Shachnev <mitya57@gmail.com>
Date: Thu May 8 18:35:14 2014 +0400
Update documentation as well
$ python2 --version
Python 2.7.3
$ pip list | grep pycrypto
pycrypto (2.6.1)
$ python2 -c "import struct; print(struct.unpack('>I', bytearray((0, 0, 0, 0))))"
Traceback (most recent call last):
File "<string>", line 1, in <module>
struct.error: unpack requires a string argument of length 4
$ python2 -c "import struct; print(struct.unpack('>I', str(bytearray((0, 0, 0, 0)))))"
(0,)
$ PYTHONPATH=. python3 tests/test_dhcrypto.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.000s
OK
$ git log -n1
commit eb6046236de59313f50232c2a4c94f6a94aaff4e
Author: Dmitry Shachnev <mitya57@gmail.com>
Date: Thu May 8 18:35:14 2014 +0400
Update documentation as well
$ python3 --version
Python 3.2.3
$ pip list | grep pycrypto
pycrypto (2.6.1)
$ python3 -c "import struct; print(struct.unpack('>I', bytearray((0, 0, 0, 0))))"
(0,)
$ python3 -c "import struct; print(struct.unpack('>I', str(bytearray((0, 0, 0, 0)))))"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: 'str' does not support the buffer interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment