comparison MoinMoin/util/moinoid.py @ 4363:817d99d715fe

remove direct usage of deprecated sha module - use hashlib, if possible
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 03 Oct 2008 22:33:35 +0200
parents a48929a5036c
children 500f68d3e2fd
comparison
equal deleted inserted replaced
4362:adec0c4861f7 4363:817d99d715fe
3 3
4 @copyright: 2006, 2007 Johannes Berg <johannes@sipsolutions.net> 4 @copyright: 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
5 @license: GNU GPL, see COPYING for details. 5 @license: GNU GPL, see COPYING for details.
6 """ 6 """
7 7
8 from sha import sha
9 from random import randint 8 from random import randint
10 import time 9 import time
11 10
12 from openid import oidutil 11 from openid import oidutil
13 from openid.store.interface import OpenIDStore 12 from openid.store.interface import OpenIDStore
14 from openid.association import Association 13 from openid.association import Association
15 from openid.store import nonce 14 from openid.store import nonce
16 15
17 from MoinMoin import caching 16 from MoinMoin import caching
17 from MoinMoin.support.python_compatibility import hash_new
18 18
19 from MoinMoin import log 19 from MoinMoin import log
20 logging = log.getLogger(__name__) 20 logging = log.getLogger(__name__)
21 21
22 # redirect openid logging to moin log 22 # redirect openid logging to moin log
51 self.request = request 51 self.request = request
52 OpenIDStore.__init__(self) 52 OpenIDStore.__init__(self)
53 53
54 def key(self, url): 54 def key(self, url):
55 '''return cache key''' 55 '''return cache key'''
56 return sha(url).hexdigest() 56 return hash_new('sha1', url).hexdigest()
57 57
58 def storeAssociation(self, server_url, association): 58 def storeAssociation(self, server_url, association):
59 ce = caching.CacheEntry(self.request, 'openid', self.key(server_url), 59 ce = caching.CacheEntry(self.request, 'openid', self.key(server_url),
60 scope='wiki', use_pickle=True) 60 scope='wiki', use_pickle=True)
61 if ce.exists(): 61 if ce.exists():
102 else: 102 else:
103 ce.remove() 103 ce.remove()
104 104
105 def useNonce(self, server_url, timestamp, salt): 105 def useNonce(self, server_url, timestamp, salt):
106 val = ''.join([str(server_url), str(timestamp), str(salt)]) 106 val = ''.join([str(server_url), str(timestamp), str(salt)])
107 csum = sha(val).hexdigest() 107 csum = hash_new('sha1', val).hexdigest()
108 ce = caching.CacheEntry(self.request, 'openid-nonce', csum, 108 ce = caching.CacheEntry(self.request, 'openid-nonce', csum,
109 scope='farm', use_pickle=False) 109 scope='farm', use_pickle=False)
110 if ce.exists(): 110 if ce.exists():
111 # nonce already used! 111 # nonce already used!
112 return False 112 return False