Clean up the namespace.
[fides] / lib / fides.h
1 /* fides.h - Light-weight, decentralised trust and authorisation management
2    Copyright (C) 2008-2009  Guus Sliepen <guus@tinc-vpn.org>
3   
4    Fides is free software; you can redistribute it and/or modify
5    it under the terms of the GNU Lesser General Public License as
6    published by the Free Software Foundation; either version 2.1 of
7    the License, or (at your option) any later version.
8   
9    Fides is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU Lesser General Public License for more details.
13   
14    You should have received a copy of the GNU Lesser General Public
15    License along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef __FIDES_H__
19 #define __FIDES_H__
20
21 #include <stdexcept>
22 #include <sys/time.h>
23 #include <map>
24 #include <vector>
25
26 #include "certificate.h"
27 #include "publickey.h"
28 #include "privatekey.h"
29 #include "utility.h"
30
31 namespace Fides {
32         class exception: public std::runtime_error {
33                 public:
34                 exception(const std::string reason): runtime_error(reason) {}
35         };
36
37         class Manager {
38                 std::string homedir;
39                 std::string certdir;
40                 std::string obsoletedir;
41                 std::string keydir;
42
43                 bool firstrun;
44                 struct timeval latest;
45
46                 private:
47                 PrivateKey mykey;
48                 std::map<std::string, PublicKey *> keys;
49                 std::map<std::string, Certificate *> certs;
50
51                 void merge(Certificate *cert);
52                 void merge(PublicKey *key);
53
54                 public:
55                 Manager(const std::string &homedir = "");
56                 ~Manager();
57
58                 bool is_firstrun() const;
59                 bool fsck() const;
60                 std::string get_homedir() const;
61
62                 void sign(const std::string &statement);
63
64                 void allow(const std::string &statement, const PublicKey *key = 0);
65                 void dontcare(const std::string &statement, const PublicKey *key = 0);
66                 void deny(const std::string &statement, const PublicKey *key = 0);
67                 bool is_allowed(const std::string &statement, const PublicKey *key = 0) const;
68                 bool is_denied(const std::string &statement, const PublicKey *key = 0) const;
69
70                 void auth_stats(const std::string &statement, int &self, int &trusted, int &all) const;
71                 void trust(const PublicKey *key);
72                 void dctrust(const PublicKey *key);
73                 void distrust(const PublicKey *key);
74                 bool is_trusted(const PublicKey *key) const;
75                 bool is_distrusted(const PublicKey *key) const;
76                 PublicKey *find_key(const std::string &fingerprint) const;
77                 void update_trust();
78
79                 std::vector<const Certificate *> find_certificates(const PublicKey *key, const std::string &statement) const;
80                 std::vector<const Certificate *> find_certificates(const std::string &statement) const;
81                 std::vector<const Certificate *> find_certificates(const PublicKey *key) const;
82
83                 const Certificate *import_certificate(const std::string &Certificate);
84                 std::string export_certificate(const Certificate *) const;
85
86                 const PublicKey *import_key(const std::string &key);
87                 std::string export_key(const PublicKey *key) const;
88
89                 void import_all(std::istream &in);
90                 void export_all(std::ostream &out) const;
91
92                 Certificate *certificate_from_string(const std::string &Certificate);
93                 Certificate *certificate_load(const std::string &filename);
94                 void certificate_save(const Certificate *cert, const std::string &filename) const;
95
96         };
97 }
98
99 #endif