core: misc improvments:

- added some constants for message types and presence
    - removed profile authentification specific methods in favor of a more generic "validated" key
This commit is contained in:
Goffi 2014-12-10 18:36:11 +01:00
commit 05e5e1448b
2 changed files with 35 additions and 14 deletions

View file

@ -332,8 +332,11 @@ class Memory(object):
def getProfileName(self, profile_key, return_profile_keys=False):
"""Return name of profile from keyword
@param profile_key: can be the profile name or a keywork (like @DEFAULT@)
@return: profile name or None if it doesn't exist"""
@param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller
@return: requested profile name or emptry string if it doesn't exist
"""
return self.params.getProfileName(profile_key, return_profile_keys)
def asyncCreateProfile(self, name, password=''):
@ -342,6 +345,10 @@ class Memory(object):
@param password: profile password
@return: Deferred
"""
if not name:
raise ValueError("Empty profile name")
if name[0] == '@':
raise ValueError("A profile name can't start with a '@'")
personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict
self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam
d = self.params.asyncCreateProfile(name)
@ -579,7 +586,7 @@ class Memory(object):
try:
del self._entities_cache[profile][entity]
except KeyError:
log.debug("Can't delete entity [%s]: not in cache" % entity.full())
log.warning(_("Can't delete entity [{}]: not in cache").format(entity.full()))
def encryptValue(self, value, profile):
"""Encrypt a value for the given profile. The personal key must be loaded

View file

@ -179,7 +179,7 @@ class Params(object):
return defer.fail(Failure(exceptions.ConnectedProfileError))
return self.storage.deleteProfile(profile)
def getProfileName(self, profile_key, return_profile_keys = False):
def getProfileName(self, profile_key, return_profile_keys=False):
"""return profile according to profile_key
@param profile_key: profile name or key which can be