]>
git.datanom.net - securemail.git/blob - user.py
1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2018 Michael Rasmussen <mir@datanom.net>
5 # This file is part of SecureMail.
7 # SecureMail is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # SecureMail is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with SecureMail. If not, see <https://www.gnu.org/licenses/>.
21 import cPickle
as pickle
24 from db
import DBInterface
as DBI
25 from cryptonize
import Cryptonize
27 class NoSuchUserException(Exception):
32 Class implementing the backend users
34 def __init__(self
, key
=None):
40 cipher
= crypto
.symmetric_encrypt(key
, pickle
.dumps(self
.__dict
__))
41 DBI
.store_user(crypto
.generate_hash(key
), cipher
)
45 cipher
= DBI
.load_user(crypto
.generate_hash(key
))
47 raise NoSuchUserException('{0}: User not found'.format(key
))
48 plain
= crypto
.symmetric_decrypt(key
, cipher
)
50 obj
= pickle
.loads(plain
)
51 self
.__dict
__.update(obj
)
52 except pickle
.UnpicklingError
as e
:
53 raise NoSuchUserException(e
)
68 def email(self
, email
):
72 if __name__
== '__main__':
75 for attr
, value
in u
.__dict
__.items():
76 print ('{0}: {1}'.format(attr
, value
))
78 key
= 'æselØre' #c.get_random_key()
79 cipher
= c
.symmetric_encrypt(key
, pickle
.dumps(u
))
80 obj
= pickle
.loads(c
.symmetric_decrypt(key
, cipher
))
81 for attr
, value
in obj
.__dict
__.items():
82 print ('{0}: {1}'.format(attr
, value
))
83 except NoSuchUserException
:
86 u
.email
= 'testname@securemail.icu'
88 except Exception as e
:
This page took 0.06585 seconds and 6 git commands to generate.