X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=lib%2Ffides.h;h=569f87619fea8a6094ee94c8b6a7651fbed7dea9;hb=0f3083b8693bfaddc4bf3fd6ce7174ac06afa958;hp=f5137694d7159f9994bf001ba7f9daaf9a083cda;hpb=406a506e2cb5e69789aef20e145b47e36a778543;p=fides diff --git a/lib/fides.h b/lib/fides.h index f513769..569f876 100644 --- a/lib/fides.h +++ b/lib/fides.h @@ -43,6 +43,12 @@ class fides { static std::string hexencode(const std::string &in); static std::string hexdecode(const std::string &in); + /// Compiled regular expression. + + /// This class holds a compiled regular expression, + /// which can be used to match arbitrary strings to. + /// It is a wrapper for the POSIX regex functions + /// regcomp() and regexec(). class regexp { regex_t comp; @@ -53,10 +59,22 @@ class fides { static const int NEWLINE = REG_NEWLINE; static const int NOTBOL = REG_NOTBOL; - static const int NOTEAL = REG_NOTEOL; - + static const int NOTEOL = REG_NOTEOL; + + /// Construct a compiled regular expression. + /// + /// @param exp Regular expression to compile. + /// @param cflags Bitwise OR of options to apply when compiling the regular expression: + /// - fides::regexp::EXTENDED + /// Use POSIX Extended Regular Expression syntax when interpreting exp. + /// - fides::regexp::ICASE + /// Make the expression case-insensitive. + /// - fides::regexp::NOSUB + /// Disable support for substring addressing. + /// - fides::regexp::NEWLINE + /// Do not treat the newline character as the start or end of a line. regexp(const std::string &exp, int cflags = 0) { - int err = regcomp(&comp, exp.c_str(), cflags | NOSUB); + int err = regcomp(&comp, exp.c_str(), cflags); if(err) throw exception("Could not compile regular expression"); } @@ -65,13 +83,20 @@ class fides { regfree(&comp); } + /// Test whether a string matches the regular expression. + /// + /// @param in String to test. + /// @param eflags Bitwise OR of options to apply when matching the string: + /// - fides::regexp::NOTBOL + /// Do not treat the start of the string as the start of a line. + /// - fides::regexp::NOTEOL + /// Do not treat the end of the string as the end of a line. + /// @return True if the string matches the regular expression, false otherwise. bool match(const std::string &in, int eflags = 0) { return regexec(&comp, in.c_str(), 0, 0, eflags) == 0; } }; - // Exception class - class exception: public std::runtime_error { public: exception(const std::string reason): runtime_error(reason) {} @@ -116,6 +141,8 @@ class fides { class certificate { friend class fides; + + /// Public key that signed this certificate. const publickey *signer; struct timeval timestamp; std::string statement; @@ -136,7 +163,6 @@ class fides { privatekey mykey; std::map keys; std::map certs; - std::set trustedkeys; void merge(certificate *cert); void merge(publickey *key); @@ -166,14 +192,14 @@ class fides { publickey *find_key(const std::string &fingerprint) const; void update_trust(); - std::vector find_certificates(const publickey *key, const std::string &statement) const; - std::vector find_certificates(const std::string &statement) const; - std::vector find_certificates(const publickey *key) const; + std::vector find_certificates(const publickey *key, const std::string &statement) const; + std::vector find_certificates(const std::string &statement) const; + std::vector find_certificates(const publickey *key) const; - certificate *import_certificate(const std::string &certificate); + const certificate *import_certificate(const std::string &certificate); std::string export_certificate(const certificate *) const; - publickey *import_key(const std::string &key); + const publickey *import_key(const std::string &key); std::string export_key(const publickey *key) const; void import_all(std::istream &in);