Show
Ignore:
Timestamp:
06/16/09 04:16:29 (14 months ago)
Author:
lars
Message:

* use "hashlib" instead of "sha" (deprecated since python2.6) if available

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cryptobox/core/settings.py

    r1158 r1177  
    444444        """Load the user database file if it exists. 
    445445        """ 
    446         import StringIO, sha 
     446        import StringIO 
     447        try: 
     448            # hashlib is available since python2.5 
     449            import hashlib 
     450            get_hash_obj = lambda text: hashlib.sha1(text) 
     451        except ImportError: 
     452            # sha is deprecated since python2.6 
     453            import sha 
     454            get_hash_obj = lambda text: sha.new(text) 
    447455        user_db_rules = StringIO.StringIO(self.userDatabaseSpec) 
    448456        try: 
     
    469477        user_db.validate(validate.Validator()) 
    470478        ## define password hash function - never use "sha" directly - SPOT 
    471         user_db.get_digest = lambda password: sha.new(password).hexdigest() 
     479        user_db.get_digest = lambda password: get_hash_obj(password).hexdigest() 
    472480        return user_db 
    473481