[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-recutils] [PATCH] src: always provide encryption routines and their
From: |
Michał Masłowski |
Subject: |
[bug-recutils] [PATCH] src: always provide encryption routines and their prototypes. |
Date: |
Thu, 22 Mar 2012 20:29:52 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Hello,
this patch solves two problems: --disable-encryption changed the librec
ABI, and rec.h wouldn't have declared encryption routines without
config.h being included before.
With the patch rec-crypt.c has warnings for unused parameters when
encryption is disabled, I'm not sure if or how this should be changed.
2012-03-22 Michał Masłowski <address@hidden>
src: always provide encryption routines and their prototypes.
* src/Makefile.am: Unconditionalize building rec-crypt.c.
* src/rec-crypt.c [!REC_CRYPT_SUPPORT]: Change to build without
encryption support by making all methods return error status.
* src/rec.h: Unconditionalize encryption routine declarations.
From 05459e4879178824a1dfcbec79f5c45e9b3000f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= <address@hidden>
Date: Thu, 22 Mar 2012 19:36:37 +0100
Subject: [PATCH] src: always provide encryption routines and their
prototypes.
This makes the ABI of librec not depend on REC_CRYPT_SUPPORT, so
programs linking to librec don't need to be recompiled to use
encryption or the library without it enabled. A side effect of this
change is rec.h declaring encryption routines when not including
config.h before, like it would be done in external programs using the
library.
---
src/Makefile.am | 7 ++-----
src/rec-crypt.c | 48 ++++++++++++++++++++++++++++++++++++++----------
src/rec.h | 7 +++----
3 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 6832092..8ab5c39 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,11 +42,8 @@ librec_la_SOURCES = rec.c \
rec-sex.c \
rec-fex.c \
rec-types.c \
- rec-buf.c
-
-if CRYPT
- librec_la_SOURCES += rec-crypt.c
-endif
+ rec-buf.c \
+ rec-crypt.c
BUILT_SOURCES = rec-sex-tab.h
AM_YFLAGS = -d
diff --git a/src/rec-crypt.c b/src/rec-crypt.c
index 6407fad..614de9f 100644
--- a/src/rec-crypt.c
+++ b/src/rec-crypt.c
@@ -25,17 +25,21 @@
#include <config.h>
-#include <string.h>
-#include <gcrypt.h>
-#include <crc.h>
-#include <base64.h>
+#ifdef REC_CRYPT_SUPPORT
+# include <string.h>
+# include <gcrypt.h>
+# include <crc.h>
+# include <base64.h>
+#endif
#include <rec.h>
#include <rec-utils.h>
+#ifdef REC_CRYPT_SUPPORT
/* Size of a block in AES128 */
-#define AESV2_BLKSIZE 16
-#define AESV2_KEYSIZE 16
+# define AESV2_BLKSIZE 16
+# define AESV2_KEYSIZE 16
+#endif
bool
rec_encrypt (char *in,
@@ -44,6 +48,7 @@ rec_encrypt (char *in,
char **out,
size_t *out_size)
{
+#ifdef REC_CRYPT_SUPPORT
gcry_cipher_hd_t handler;
size_t i;
size_t password_size;
@@ -62,9 +67,9 @@ rec_encrypt (char *in,
crc = crc32 (in, in_size);
-#if defined WORDS_BIGENDIAN
+# if defined WORDS_BIGENDIAN
crc = rec_endian_swap (crc);
-#endif
+# endif
real_in_size = in_size + 4;
real_in = malloc (real_in_size + 4);
@@ -142,6 +147,9 @@ rec_encrypt (char *in,
gcry_cipher_close (handler);
return true;
+#else
+ return false;
+#endif /* !REC_CRYPT_SUPPORT */
}
bool
@@ -151,6 +159,7 @@ rec_decrypt (char *in,
char **out,
size_t *out_size)
{
+#ifdef REC_CRYPT_SUPPORT
gcry_cipher_hd_t handler;
size_t i;
size_t password_size;
@@ -213,9 +222,9 @@ rec_decrypt (char *in,
uint32_t crc = 0;
memcpy (&crc, *out + strlen(*out) - 4, 4);
-#if defined WORDS_BIGENDIAN
+# if defined WORDS_BIGENDIAN
crc = rec_endian_swap (crc);
-#endif
+# endif
if (crc32 (*out, strlen(*out) - 4) != crc)
{
@@ -233,6 +242,9 @@ rec_decrypt (char *in,
gcry_cipher_close (handler);
return true;
+#else
+ return false;
+#endif /* !REC_CRYPT_SUPPORT */
}
bool
@@ -240,6 +252,7 @@ rec_encrypt_record (rec_rset_t rset,
rec_record_t record,
const char *password)
{
+#ifdef REC_CRYPT_SUPPORT
rec_field_t field;
bool res;
const char *field_name;
@@ -272,12 +285,16 @@ rec_encrypt_record (rec_rset_t rset,
}
return res;
+#else
+ return false;
+#endif /* !REC_CRYPT_SUPPORT */
}
bool
rec_encrypt_field (rec_field_t field,
const char *password)
{
+#ifdef REC_CRYPT_SUPPORT
char *field_value;
char *field_value_encrypted;
char *field_value_base64;
@@ -340,12 +357,16 @@ rec_encrypt_field (rec_field_t field,
free (field_value_base64);
return true;
+#else
+ return false;
+#endif /* !REC_CRYPT_SUPPORT */
}
bool
rec_decrypt_field (rec_field_t field,
const char *password)
{
+#ifdef REC_CRYPT_SUPPORT
const char *field_value;
char *base64_decoded;
size_t base64_decoded_size;
@@ -391,6 +412,9 @@ rec_decrypt_field (rec_field_t field,
}
return true;
+#else
+ return false;
+#endif /* !REC_CRYPT_SUPPORT */
}
bool
@@ -398,6 +422,7 @@ rec_decrypt_record (rec_rset_t rset,
rec_record_t record,
const char *password)
{
+#ifdef REC_CRYPT_SUPPORT
bool res = true;
size_t i, num_fields, k;
rec_field_t field;
@@ -424,6 +449,9 @@ rec_decrypt_record (rec_rset_t rset,
}
return res;
+#else
+ return false;
+#endif /* !REC_CRYPT_SUPPORT */
}
/* End of rec-crypt.c */
diff --git a/src/rec.h b/src/rec.h
index cbcc62f..242368e 100644
--- a/src/rec.h
+++ b/src/rec.h
@@ -1998,12 +1998,13 @@ char *rec_sex_eval_str (rec_sex_t sex, rec_record_t
record);
void rec_sex_print_ast (rec_sex_t sex);
-#if defined REC_CRYPT_SUPPORT
-
/*
* ENCRYPTION
*
* The following routines encrypt and decrypt fields in rec data.
+ *
+ * If librec was built without encryption support, all of them will do
+ * nothing and return 'false' as if an error occurred.
*/
/* Prefix used in the encrypted and ASCII encoded field values, which
@@ -2068,8 +2069,6 @@ bool rec_decrypt_field (rec_field_t field, const char
*password);
bool rec_decrypt_record (rec_rset_t rset, rec_record_t record,
const char *password);
-#endif /* REC_CRYPT_SUPPORT */
-
#endif /* !GNU_REC_H */
/* End of rec.h */
--
1.7.9.4
pgp8kwvZB7zHn.pgp
Description: PGP signature
- [bug-recutils] [PATCH] src: always provide encryption routines and their prototypes.,
Michał Masłowski <=