Split the libary into multiple files, in general one per class.
[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 fides {
33                 std::string homedir;
34                 std::string certdir;
35                 std::string obsoletedir;
36                 std::string keydir;
37
38                 bool firstrun;
39                 struct timeval latest;
40
41                 public:
42                 // Utility functions
43
44                 class exception: public std::runtime_error {
45                         public:
46                         exception(const std::string reason): runtime_error(reason) {}
47                 };
48                 // Fides class itself
49
50                 private:
51                 privatekey mykey;
52                 std::map<std::string, publickey *> keys;
53                 std::map<std::string, certificate *> certs;
54
55                 void merge(certificate *cert);
56                 void merge(publickey *key);
57
58                 public:
59                 fides(const std::string &homedir = "");
60                 ~fides();
61
62                 bool is_firstrun() const;
63                 bool fsck() const;
64                 std::string get_homedir() const;
65
66                 void sign(const std::string &statement);
67
68                 void allow(const std::string &statement, const publickey *key = 0);
69                 void dontcare(const std::string &statement, const publickey *key = 0);
70                 void deny(const std::string &statement, const publickey *key = 0);
71                 bool is_allowed(const std::string &statement, const publickey *key = 0) const;
72                 bool is_denied(const std::string &statement, const publickey *key = 0) const;
73
74                 void auth_stats(const std::string &statement, int &self, int &trusted, int &all) const;
75                 void trust(const publickey *key);
76                 void dctrust(const publickey *key);
77                 void distrust(const publickey *key);
78                 bool is_trusted(const publickey *key) const;
79                 bool is_distrusted(const publickey *key) const;
80                 publickey *find_key(const std::string &fingerprint) const;
81                 void update_trust();
82
83                 std::vector<const certificate *> find_certificates(const publickey *key, const std::string &statement) const;
84                 std::vector<const certificate *> find_certificates(const std::string &statement) const;
85                 std::vector<const certificate *> find_certificates(const publickey *key) const;
86
87                 const certificate *import_certificate(const std::string &certificate);
88                 std::string export_certificate(const certificate *) const;
89
90                 const publickey *import_key(const std::string &key);
91                 std::string export_key(const publickey *key) const;
92
93                 void import_all(std::istream &in);
94                 void export_all(std::ostream &out) const;
95
96                 certificate *certificate_from_string(const std::string &certificate);
97                 certificate *certificate_load(const std::string &filename);
98                 void certificate_save(const certificate *cert, const std::string &filename) const;
99
100         };
101 }
102
103 #endif