Share

Python Cryptographic Toolkit

Tracker: Bugs

5 Type string in aes.py - ID: 900110
Last Update: Comment added ( nuddelaug )

In aes.py there is 4 time this code:
if str(type(data)) != "<type 'string'>":

With python 2.3, it doesn't work, much better to use:
if str(type(data)) != str(type("")):


Marco Beri ( marcoberi ) - 2004-02-19 09:03

5

Open

Duplicate

Nobody/Anonymous

None

None

Public


Comments ( 4 )




Date: 2006-04-29 15:28
Sender: nuddelaug

Logged In: YES
user_id=1216160

heres a patch to get it work with any version of Python
using the provided Types Module and not string compare ;)

--- aes/src/aes.py 2001-11-30 17:30:04.000000000 +0100
+++ /usr/lib/python2.3/site-packages/aes/aes.py 2006-04-29
17:18:30.000000000 +0200
@@ -37,6 +37,7 @@
#
#====================================================================

+from types import *
from rijndaelc import *

noSHA256=0
@@ -189,7 +190,7 @@
The encrypted string (with NULL bytes) is returned.
"""

- if str(type(data)) != "<type 'string'>":
+ if type(data) != StringType:
raise TypeError('Data to encrypt must be a string')

if not self.keyMaterial:
@@ -210,7 +211,7 @@
you, check the key you're using!
"""

- if str(type(data)) != "<type 'string'>":
+ if type(data) != StringType:
raise TypeError('Data to decrypt must be a string')

if not self.keyMaterial:
@@ -236,7 +237,7 @@
if noSHA256:
raise RuntimeError("Need sha256 module to lazyEncrypt")

- if str(type(data)) != "<type 'string'>":
+ if type(data) != StringType:
raise TypeError('Data to encrypt must be a string')

hasher = sha256()
@@ -266,7 +267,7 @@
if noSHA256:
raise RuntimeError("Need sha256 module to lazyDecrypt")

- if str(type(data)) != "<type 'string'>":
+ if type(data) != StringType:
raise TypeError('Data to decrypt must be a string')

hasher = sha256()


Date: 2004-06-14 15:16
Sender: nobody

Logged In: NO

or rather,
if type(data) != str:

seems to work with all snake types.


Date: 2004-04-12 20:06
Sender: nobody

Logged In: NO

Replace
if str(type(data)) != "<type 'string'>"
With
if str(type(data)) != "<type 'string'>" and
str(type(data)) != "<type 'str'>":

Also occurences in sha256


Date: 2004-02-19 09:04
Sender: marcoberi

Logged In: YES
user_id=588604

Oooppsss... sorry.
It's dupe.


Log in to comment.




Attached File

No Files Currently Attached

Change ( 1 )

Field Old Value Date By
resolution_id None 2004-02-19 09:04 marcoberi