fsb: Add hardware token authentication support.
[fulbank.git] / fulbank / data.py
CommitLineData
717d54fc
FT
1import hashlib
2
3def _localname(type):
4 mod = type.__module__
5 if mod.startswith("fulbank."):
6 mod = mod[8:]
7 return "%s.%s" % (mod, type.__name__)
8
9class account(object):
10 @property
11 def number(self): raise NotImplementedError("account.number")
12 @property
13 def name(self): raise NotImplementedError("account.name")
14 def transactions(self): raise NotImplementedError("account.transactions")
15
16 def __repr__(self):
17 return "#<%s %s: %r>" % (_localname(type(self)), self.number, self.name)
18
19class txnaccount(account):
20 @property
21 def balance(self): raise NotImplementedError("txnaccount.balance")
22 @property
23 def clearing(self): raise NotImplementedError("txnaccount.clearing")
24 @property
25 def fullnumber(self): raise NotImplementedError("txnaccount.fullnumber")
26
27class cardaccount(account):
28 pass
29
30class transaction(object):
31 @property
32 def value(self): raise NotImplementedError("transaction.value")
33 @property
34 def message(self): raise NotImplementedError("transaction.message")
35 @property
36 def date(self): raise NotImplementedError("transaction.date")
37
38 @property
39 def hash(self):
40 dig = hashlib.sha256()
41 dig.update(str(self.date.toordinal()).encode("ascii") + b"\0")
42 dig.update(self.message.encode("utf-8") + b"\0")
43 dig.update(str(self.value.amount).encode("ascii") + b"\0")
44 dig.update(self.value.currency.symbol.encode("ascii") + b"\0")
45 return dig.hexdigest()
46
47 def __repr__(self):
48 return "#<%s %s: %r>" % (_localname(type(self)), self.value, self.message)