From 132aa0db633c711bd027565931fe6995d19b55e5 Mon Sep 17 00:00:00 2001 From: Sam Scott Date: Tue, 19 Dec 2017 23:43:45 +0000 Subject: [PATCH] Change header language to cpp. --- libpasta-capi/build.rs | 2 +- libpasta-capi/ctest/compile.sh | 2 +- libpasta-capi/ctest/{test.c => test.cpp} | 4 +-- libpasta-capi/include/pasta-bindings.h | 45 ++++++++++++------------ 4 files changed, 26 insertions(+), 27 deletions(-) rename libpasta-capi/ctest/{test.c => test.cpp} (89%) diff --git a/libpasta-capi/build.rs b/libpasta-capi/build.rs index 84d5395..4d2899c 100644 --- a/libpasta-capi/build.rs +++ b/libpasta-capi/build.rs @@ -7,7 +7,7 @@ use cbindgen::{Builder, Config, Language}; fn main() { let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let config = Config { language: Language::C, .. Config::default() }; + let config = Config { language: Language::Cxx, .. Config::default() }; Builder::new() .with_crate(crate_dir) diff --git a/libpasta-capi/ctest/compile.sh b/libpasta-capi/ctest/compile.sh index 904dcdb..994dd9a 100644 --- a/libpasta-capi/ctest/compile.sh +++ b/libpasta-capi/ctest/compile.sh @@ -3,4 +3,4 @@ set -ex cargo build --release --manifest-path ../Cargo.toml -gcc -DDEBUG -g -o test test.c -Wall -I../include -L../target/release -lpasta +g++ -DDEBUG -g -o test test.cpp -Wall -I../include -L../target/release -lpasta diff --git a/libpasta-capi/ctest/test.c b/libpasta-capi/ctest/test.cpp similarity index 89% rename from libpasta-capi/ctest/test.c rename to libpasta-capi/ctest/test.cpp index 5461a97..e9d2548 100644 --- a/libpasta-capi/ctest/test.c +++ b/libpasta-capi/ctest/test.cpp @@ -12,12 +12,12 @@ void test_hash_and_verify() { } void test_migrate() { - char *hash = "$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"; + char *hash = (char *)"$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"; hash = migrate_hash(hash); // printf("New hash: %s\n", hash); free_string(hash); - hash = "$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"; + hash = (char *)"$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"; char *newhash; bool res = verify_password_update_hash_in_place(hash, "my password", &newhash); assert (res); diff --git a/libpasta-capi/include/pasta-bindings.h b/libpasta-capi/include/pasta-bindings.h index 80635dd..79ec670 100644 --- a/libpasta-capi/include/pasta-bindings.h +++ b/libpasta-capi/include/pasta-bindings.h @@ -1,26 +1,23 @@ -#include -#include -#include - -/* - * Holds possible configuration options - * See the [module level documentation](index.html) for more information. - */ -typedef struct Config Config; - -/* - * Password hashing primitives - * - * Each variant is backed up by different implementation. - * Internally, primitives can either be static values, for example, - * the `lazy_static` generated value `DEFAULT_PRIM`, or dynamically allocated - * variables, which are `Arc>`. - * - * Most operations are expected to be performed using the static functions, - * since most use the default algorithms. However, the flexibilty to support - * arbitrary parameter sets is essential. - */ -typedef struct Primitive Primitive; +#include +#include + +// Holds possible configuration options +// See the [module level documentation](index.html) for more information. +struct Config; + +// Password hashing primitives +// +// Each variant is backed up by different implementation. +// Internally, primitives can either be static values, for example, +// the `lazy_static` generated value `DEFAULT_PRIM`, or dynamically allocated +// variables, which are `Arc>`. +// +// Most operations are expected to be performed using the static functions, +// since most use the default algorithms. However, the flexibilty to support +// arbitrary parameter sets is essential. +struct Primitive; + +extern "C" { char *config_hash_password(const Config *config, const char *password); @@ -64,3 +61,5 @@ char *read_password(const char *prompt); bool verify_password(const char *hash, const char *password); bool verify_password_update_hash_in_place(const char *hash, const char *password, char **new_hash); + +} // extern "C"