Install a pkg-config file.
[fides] / lib / certificate.cc
index 9b83ec0..5230772 100644 (file)
@@ -15,6 +15,7 @@
    License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <cstdio>
 #include <string>
 
 #include "certificate.h"
@@ -22,8 +23,8 @@
 
 using namespace std;
 
-namespace fides {
-       /// \class fides::certificate
+namespace Fides {
+       /// \class Certificate
        ///
        /// \brief Representation of a certificate.
 
@@ -33,12 +34,12 @@ namespace fides {
        /// @param timestamp  Timestamp of the certificate.
        /// @param statement  Statement of the certificate.
        /// @param signature  Signature of the certificate.
-       certificate::certificate(const publickey *key, struct timeval timestamp, const std::string &statement, const std::string &signature): signer(key), timestamp(timestamp), statement(statement), signature(signature) {}
+       Certificate::Certificate(const PublicKey *key, struct timeval timestamp, const std::string &statement, const std::string &signature): signer(key), timestamp(timestamp), statement(statement), signature(signature) {}
 
        /// Verifies the signature of the certificate.
        //
        /// @return True if the signature is valid, false otherwise.
-       bool certificate::validate() const {
+       bool Certificate::validate() const {
                string data = signer->fingerprint(256);
                data += string((const char *)&timestamp, sizeof timestamp);
                data += statement;
@@ -50,7 +51,7 @@ namespace fides {
        /// @param key        Private key to sign the certificate with.
        /// @param timestamp  Timestamp of the certificate.
        /// @param statement  Statement of the certificate.
-       certificate::certificate(const privatekey *key, struct timeval timestamp, const std::string &statement): signer(key), timestamp(timestamp), statement(statement) {
+       Certificate::Certificate(const PrivateKey *key, struct timeval timestamp, const std::string &statement): signer(key), timestamp(timestamp), statement(statement) {
                string data = signer->fingerprint(256);
                data += string((const char *)&timestamp, sizeof timestamp);
                data += statement;
@@ -62,14 +63,14 @@ namespace fides {
        /// @param bits Number of bits from the fingerprint to return.
        ///             The number will be rounded down to the nearest multiple of 8.
        /// @return String containing the fingerprint.
-       string certificate::fingerprint(unsigned int bits) const {
+       string Certificate::fingerprint(unsigned int bits) const {
                return signature.substr(signature.size() - bits / 8);   
        }
 
        /// Write the certificate to a string.
        //
        /// @return String containing the certificate in textual format.
-       string certificate::to_string() const {
+       string Certificate::to_string() const {
                string data = hexencode(signer->fingerprint());
                data += ' ';
                char ts[100];
@@ -82,3 +83,30 @@ namespace fides {
                return data;
        }
 }
+
+// C bindings
+
+fides_certificate *fides_certificate_new(const fides_publickey *pub, struct timeval timestamp, const char *statement, const char *signature) {
+       return new Fides::Certificate(pub, timestamp, statement, signature);
+}
+
+fides_certificate *fides_certificate_new_priv(const fides_privatekey *priv, struct timeval timestamp, const char *statement) {
+       return new Fides::Certificate(priv, timestamp, statement);
+}
+
+void fides_certificate_free(fides_certificate *c) {
+       delete c;
+}
+
+
+char *fides_certificate_to_string(fides_certificate *c) {
+       return strdup(c->to_string().c_str());
+}
+
+char *fides_certificate_fingerprint(fides_certificate *c, unsigned int bits) {
+       return strdup(c->fingerprint(bits).c_str());
+}
+
+bool fides_certificate_validate(fides_certificate *c) {
+       return c->validate();
+}