Menu

#6 Type string in aes.py

open-duplicate
nobody
None
5
2004-02-19
2004-02-19
Marco Beri
No

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("")):

Discussion

  • Marco Beri

    Marco Beri - 2004-02-19

    Logged In: YES
    user_id=588604

    Oooppsss... sorry.
    It's dupe.

     
  • Marco Beri

    Marco Beri - 2004-02-19
    • status: open --> open-duplicate
     
  • Nobody/Anonymous

    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

     
  • Nobody/Anonymous

    Logged In: NO

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

    seems to work with all snake types.

     
  • Michael Lang

    Michael Lang - 2006-04-29

    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()

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.