]> git.saurik.com Git - ldid.git/blob - ldid.hpp
Finish implementating application bundle codesign.
[ldid.git] / ldid.hpp
1 #ifndef LDID_HPP
2 #define LDID_HPP
3
4 #include <cstdlib>
5 #include <map>
6 #include <streambuf>
7 #include <string>
8
9 namespace ldid {
10
11 // I wish Apple cared about providing quality toolchains :/
12
13 template <typename Function_>
14 class Functor;
15
16 template <typename Type_, typename... Args_>
17 class Functor<Type_ (Args_...)> {
18 public:
19 virtual Type_ operator ()(Args_... args) const = 0;
20 };
21
22 template <typename Function_>
23 class FunctorImpl;
24
25 template <typename Value_, typename Type_, typename... Args_>
26 class FunctorImpl<Type_ (Value_::*)(Args_...) const> :
27 public Functor<Type_ (Args_...)>
28 {
29 private:
30 const Value_ *value_;
31
32 public:
33 FunctorImpl(const Value_ &value) :
34 value_(&value)
35 {
36 }
37
38 virtual Type_ operator ()(Args_... args) const {
39 return (*value_)(args...);
40 }
41 };
42
43 template <typename Function_>
44 FunctorImpl<decltype(&Function_::operator())> fun(const Function_ &value) {
45 return value;
46 }
47
48 class Folder {
49 public:
50 virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0;
51 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code) = 0;
52 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code) = 0;
53 };
54
55 class DiskFolder :
56 public Folder
57 {
58 private:
59 const std::string path_;
60 std::map<std::string, std::string> commit_;
61
62 std::string Path(const std::string &path);
63
64 public:
65 DiskFolder(const std::string &path);
66 ~DiskFolder();
67
68 virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
69 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code);
70 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
71 };
72
73 class SubFolder :
74 public Folder
75 {
76 private:
77 Folder *parent_;
78 std::string path_;
79
80 public:
81 SubFolder(Folder *parent, const std::string &path);
82
83 virtual void Save(const std::string &path, const Functor<void (std::streambuf &)> &code);
84 virtual bool Open(const std::string &path, const Functor<void (std::streambuf &)> &code);
85 virtual void Find(const std::string &path, const Functor<void (const std::string &, const Functor<void (const Functor<void (std::streambuf &, std::streambuf &)> &)> &)> &code);
86 };
87
88 typedef std::map<uint32_t, std::vector<char>> Slots;
89
90 void Sign(const void *idata, size_t isize, std::streambuf &output, const std::string &identifier, const std::string &entitlements, const std::string &key, const Slots &slots);
91
92 }
93
94 #endif//LDID_HPP