Hide debug function 21/69521/8
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 13 May 2016 13:15:36 +0000 (15:15 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 19 May 2016 10:29:33 +0000 (12:29 +0200)
Debug function is exported but the header is kept private.

Change-Id: I399bc52688c126a061dc29d66029bfe66d993c47

12 files changed:
api/yaca/error.h
examples/digest.c
examples/encrypt.c
examples/encrypt_aes_gcm.c
examples/key_exchange.c
examples/key_import_export.c
examples/seal.c
examples/sign.c
examples/test.c
src/debug.c [moved from src/error.c with 91% similarity]
src/debug.h [new file with mode: 0644]
todo.txt

index 64de6f7..22030dd 100644 (file)
@@ -29,7 +29,7 @@ extern "C" {
 #endif
 
 /**
- * @defgroup  Error  Yet another Crypto API - error enums and debug functions.
+ * @defgroup  Error  Yet another Crypto API - error enums.
  *
  * @{
  */
@@ -45,25 +45,9 @@ enum __yaca_error_code {
        YACA_ERROR_TOO_BIG_ARGUMENT   = -4,
        YACA_ERROR_OUT_OF_MEMORY      = -5,
        YACA_ERROR_SIGNATURE_INVALID  = -6,
-       YACA_ERROR_PASSWORD_INVALID   = -7,
+       YACA_ERROR_PASSWORD_INVALID   = -7
 };
 
-// TODO disable debug function in release?
-
-/**
- * @brief Debug callback type.
- */
-typedef void (*yaca_debug_func)(const char*);
-
-/**
- * @brief  Sets a current thread debug callback that will be called each time an
- *         internal error occurs. A NULL terminated string with location and
- *         description of the error will be passed as an argument.
- *
- * @param[in] fn  Function to set as internal error callback.
- */
-void yaca_error_set_debug_func(yaca_debug_func fn);
-
 /**@}*/
 
 #ifdef __cplusplus
index a5ef093..68c6bcb 100644 (file)
@@ -28,6 +28,7 @@
 #include <yaca/error.h>
 #include "lorem.h"
 #include "misc.h"
+#include "../src/debug.h"
 
 void digest_simple(void)
 {
@@ -80,7 +81,7 @@ exit_ctx:
 
 int main()
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        int ret = yaca_init();
        if (ret < 0)
index fe686ce..c01ab04 100644 (file)
@@ -30,6 +30,7 @@
 #include <yaca/error.h>
 #include "lorem.h"
 #include "misc.h"
+#include "../src/debug.h"
 
 void encrypt_simple(const yaca_enc_algo_e algo,
                     const yaca_block_cipher_mode_e bcm,
@@ -182,7 +183,7 @@ ex_key:
 
 int main()
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        int ret = yaca_init();
        if (ret < 0)
index 86da336..1e61bc3 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "lorem.h"
 #include "misc.h"
+#include "../src/debug.h"
 
 // Symmetric aes gcm encryption using advanced API
 void encrypt_decrypt_aes_gcm(void)
@@ -180,7 +181,7 @@ clean:
 
 int main()
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        int ret = yaca_init();
        if (ret < 0)
index 9464732..542beb8 100644 (file)
@@ -28,6 +28,7 @@
 #include <yaca/types.h>
 #include <yaca/error.h>
 #include "misc.h"
+#include "../src/debug.h"
 
 void key_exchange_dh(void)
 {
@@ -150,7 +151,7 @@ clean:
 
 int main()
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        int ret = yaca_init();
        if (ret < 0)
index 9d005c2..183068c 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 
 #include "misc.h"
+#include "../src/debug.h"
 
 #include <yaca/crypto.h>
 #include <yaca/encrypt.h>
@@ -259,7 +260,7 @@ int main()
        if (ret != 0)
                return ret;
 
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        ret = yaca_key_gen(&sym, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_1024BIT);
        if (ret != 0)
index 4da8228..5d34da1 100644 (file)
@@ -29,6 +29,7 @@
 #include <yaca/error.h>
 #include "lorem.h"
 #include "misc.h"
+#include "../src/debug.h"
 
 void encrypt_seal(void)
 {
@@ -139,7 +140,7 @@ ex_prvk:
 
 int main()
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        int ret = yaca_init();
        if (ret < 0)
index faf0131..f2ba25e 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "lorem.h"
 #include "misc.h"
+#include "../src/debug.h"
 
 // Signature creation and verification using advanced API
 void sign_verify_asym(yaca_key_type_e type, const char *algo)
@@ -202,7 +203,7 @@ finish:
 
 int main()
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        int ret = yaca_init();
        if (ret < 0)
index 4e6f7f0..a9992b2 100644 (file)
 #include <yaca/types.h>
 #include <yaca/error.h>
 #include "misc.h"
+#include "../src/debug.h"
 
 /** Simple test for development of library (before API is ready) */
 
 int main(int argc, char* argv[])
 {
-       yaca_error_set_debug_func(debug_func);
+       yaca_debug_set_error_cb(debug_func);
 
        yaca_key_h key;
        char *k;
similarity index 91%
rename from src/error.c
rename to src/debug.c
index 140d1b4..2bdaa74 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License
  */
 /*
- * @file       error.c
+ * @file       debug.c
  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
  */
 
 
 #include <yaca/error.h>
 #include "internal.h"
+#include "debug.h"
 
 // TODO any better idea than to use __thread?
-static __thread yaca_debug_func debug_fn = NULL;
+static __thread yaca_error_cb error_cb = NULL;
 static bool error_strings_loaded = false;
 
-API void yaca_error_set_debug_func(yaca_debug_func fn)
+API void yaca_debug_set_error_cb(yaca_error_cb fn)
 {
-       debug_fn = fn;
+       error_cb = fn;
 }
 
 // TODO use peeking function to intercept common errors
@@ -41,7 +42,7 @@ API void yaca_error_set_debug_func(yaca_debug_func fn)
 
 void error_dump(const char *file, int line, const char *function, int code)
 {
-       if (debug_fn == NULL)
+       if (error_cb == NULL)
                return;
 
        static const size_t BUF_SIZE = 512;
@@ -81,6 +82,6 @@ void error_dump(const char *file, int line, const char *function, int code)
        }
        buf[written] = '\0';
 
-       (*debug_fn)(buf);
+       (*error_cb)(buf);
 }
 
diff --git a/src/debug.h b/src/debug.h
new file mode 100644 (file)
index 0000000..f748d31
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file debug.h
+ * @brief
+ */
+
+#ifndef YACA_DEBUG_H
+#define YACA_DEBUG_H
+
+typedef void (*yaca_error_cb)(const char*);
+
+void yaca_debug_set_error_cb(yaca_error_cb cb);
+
+
+#endif /* YACA_DEBUG_H */
index 3ed8333..216c413 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -3,3 +3,4 @@ Global:
   In other words check whether the user won't cause a buffer overflow.
 - Importing/exporting encrypted (passphrased) RSA keys
 - Support for OCB mode was added in OpenSSL 1.1.0
+- Remove debug function from examples