Author: cmpilato
Date: Fri Apr 6 16:10:26 2012
New Revision: 1310436
URL: http://svn.apache.org/viewvc?rev=1310436&view=rev
Log:
Introduce a single #define to govern the ability of cryptographic
support (instead of relying on multiple APR/APRUtil defines), and
rework the use thereof such that exported symbols are always
available.
* subversion/libsvn_subr/crypto.h
(): Remove conditional wrapping around function and structure
definitions. These things will always be available, just perhaps
non-functional where the underlying support is lacking.
(SVN_HAVE_CRYPTO): New #define, defined only when both
APU_HAVE_CRYPTO and APR_HAS_RANDOM are defined and true.
* subversion/libsvn_subr/crypto.c
Rejigger preprocessor conditionals such that symbols exposed outside
this source file are always available (regardless of preprocessor
macro evaluations). Use SVN_HAVE_CRYPTO rather than APU_HAVE_CRYPTO
throughout.
* subversion/tests/libsvn_subr/crypto-test.c
Lose unnecessary preprocessor conditions, and update necessary ones
to use SVN_HAVE_CRYPTO rather than APU_HAVE_CRYPTO.
Suggested by: gstein
Modified:
subversion/trunk/subversion/libsvn_subr/crypto.c
subversion/trunk/subversion/libsvn_subr/crypto.h
subversion/trunk/subversion/tests/libsvn_subr/crypto-test.c
Modified: subversion/trunk/subversion/libsvn_subr/crypto.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/crypto.c?rev=1310436&r1=1310435&r2=1310436&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/crypto.c (original)
+++ subversion/trunk/subversion/libsvn_subr/crypto.c Fri Apr 6 16:10:26 2012
@@ -23,9 +23,10 @@
#include "crypto.h"
-#if APU_HAVE_CRYPTO
+#ifdef SVN_HAVE_CRYPTO
#include <apr_random.h>
#include <apr_crypto.h>
+#endif /* SVN_HAVE_CRYPTO */
#include "svn_types.h"
@@ -44,6 +45,7 @@
/* A structure for containing Subversion's cryptography-related bits
(so we can avoid passing around APR-isms outside this module). */
struct svn_crypto__ctx_t {
+#ifdef SVN_HAVE_CRYPTO
apr_crypto_t *crypto; /* APR cryptography context. */
#if 0
@@ -53,12 +55,16 @@ struct svn_crypto__ctx_t {
### apr_generate_random_bytes() to generate entropy for seeding
### apr_random_t. See httpd/server/core.c:ap_init_rng() */
apr_random_t *rand;
-#endif
+#endif /* 0 */
+#else /* SVN_HAVE_CRYPTO */
+ int unused_but_required_to_satisfy_c_compilers;
+#endif /* SVN_HAVE_CRYPTO */
};
-/*** Initialization ***/
+/*** Helper Functions ***/
+#ifdef SVN_HAVE_CRYPTO
/* One-time initialization of the cryptography subsystem. */
@@ -90,10 +96,6 @@ crypto_init(void *baton, apr_pool_t *any
}
-
-/*** Helper Functions ***/
-
-
/* If APU_ERR is non-NULL, create and return a Subversion error using
APR_ERR and APU_ERR. */
static svn_error_t *
@@ -142,7 +144,6 @@ get_random_bytes(const unsigned char **r
apr_size_t rand_len,
apr_pool_t *result_pool)
{
-#if APR_HAS_RANDOM
apr_status_t apr_err;
unsigned char *bytes;
@@ -153,19 +154,41 @@ get_random_bytes(const unsigned char **r
*rand_bytes = bytes;
return SVN_NO_ERROR;
-#else
- return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
- _("No support for random data generation found"));
-#endif
}
+/* Return an svn_string_t allocated from RESULT_POOL, with its .data
+ and .len members set to DATA and LEN, respective.
+
+ WARNING: No lifetime management of DATA is offered here, so you
+ probably want to ensure that that information is allocated in a
+ sufficiently long-lived pool (such as, for example, RESULT_POOL). */
+static const svn_string_t *
+wrap_as_string(const unsigned char *data,
+ apr_size_t len,
+ apr_pool_t *result_pool)
+{
+ svn_string_t *s = apr_palloc(result_pool, sizeof(*s));
+
+ s->data = (const char *)data; /* better already be in RESULT_POOL */
+ s->len = len;
+ return s;
+}
+
+
+#endif /* SVN_HAVE_CRYPTO */
+
+
+
+/*** Semi-public APIs ***/
+
/* Set CTX to a Subversion cryptography context allocated from
RESULT_POOL. */
svn_error_t *
svn_crypto__context_create(svn_crypto__ctx_t **ctx,
apr_pool_t *result_pool)
{
+#ifdef SVN_HAVE_CRYPTO
apr_status_t apr_err;
const apu_err_t *apu_err = NULL;
apr_crypto_t *apr_crypto;
@@ -203,25 +226,10 @@ svn_crypto__context_create(svn_crypto__c
(*ctx)->crypto = apr_crypto;
return SVN_NO_ERROR;
-}
-
-
-/* Return an svn_string_t allocated from RESULT_POOL, with its .data
- and .len members set to DATA and LEN, respective.
-
- WARNING: No lifetime management of DATA is offered here, so you
- probably want to ensure that that information is allocated in a
- sufficiently long-lived pool (such as, for example, RESULT_POOL). */
-static const svn_string_t *
-wrap_as_string(const unsigned char *data,
- apr_size_t len,
- apr_pool_t *result_pool)
-{
- svn_string_t *s = apr_palloc(result_pool, sizeof(*s));
-
- s->data = (const char *)data; /* better already be in RESULT_POOL */
- s->len = len;
- return s;
+#else /* SVN_HAVE_CRYPTO */
+ return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+ "Cryptographic support is not available");
+#endif /* SVN_HAVE_CRYPTO */
}
@@ -235,6 +243,7 @@ svn_crypto__encrypt_password(const svn_s
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
+#ifdef SVN_HAVE_CRYPTO
svn_error_t *err = SVN_NO_ERROR;
const unsigned char *salt_vector;
const unsigned char *iv_vector;
@@ -359,6 +368,10 @@ svn_crypto__encrypt_password(const svn_s
cleanup:
apr_crypto_block_cleanup(block_ctx);
return err;
+#else /* SVN_HAVE_CRYPTO */
+ return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+ "Cryptographic support is not available");
+#endif /* SVN_HAVE_CRYPTO */
}
@@ -372,6 +385,7 @@ svn_crypto__decrypt_password(const char
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
+#ifdef SVN_HAVE_CRYPTO
svn_error_t *err = SVN_NO_ERROR;
apr_status_t apr_err;
apr_crypto_block_t *block_ctx = NULL;
@@ -448,6 +462,8 @@ svn_crypto__decrypt_password(const char
cleanup:
apr_crypto_block_cleanup(block_ctx);
return err;
+#else /* SVN_HAVE_CRYPTO */
+ return svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
+ "Cryptographic support is not available");
+#endif /* SVN_HAVE_CRYPTO */
}
-
-#endif /* APU_HAVE_CRYPTO */
Modified: subversion/trunk/subversion/libsvn_subr/crypto.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/crypto.h?rev=1310436&r1=1310435&r2=1310436&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/crypto.h (original)
+++ subversion/trunk/subversion/libsvn_subr/crypto.h Fri Apr 6 16:10:26 2012
@@ -24,9 +24,15 @@
#ifndef SVN_LIBSVN_SUBR_CRYPTO_H
#define SVN_LIBSVN_SUBR_CRYPTO_H
-#include <apu.h> /* for APU_HAVE_CRYPTO */
-
+/* Test for APR crypto and RNG support */
+#undef SVN_HAVE_CRYPTO
+#include <apr.h> /* for APR_HAS_RANDOM */
+#include <apu.h> /* for APU_HAVE_CRYPTO */
+#if APR_HAS_RANDOM
#if APU_HAVE_CRYPTO
+#define SVN_HAVE_CRYPTO
+#endif
+#endif
#include "svn_types.h"
#include "svn_string.h"
@@ -89,6 +95,4 @@ svn_crypto__decrypt_password(const char
}
#endif /* __cplusplus */
-#endif /* APU_HAVE_CRYPTO */
-
-#endif /* SVN_CRYPTO_H */
+#endif /* SVN_LIBSVN_SUBR_CRYPTO_H */
Modified: subversion/trunk/subversion/tests/libsvn_subr/crypto-test.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/crypto-test.c?rev=1310436&r1=1310435&r2=1310436&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/crypto-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/crypto-test.c Fri Apr 6
16:10:26 2012
@@ -29,8 +29,6 @@
#include "../svn_test.h"
#include "../../libsvn_subr/crypto.h"
-#if APU_HAVE_CRYPTO
-
/* Helper function: encrypt PASSWORD within CTX using MASTER, then
decrypt those results and ensure the original PASSWORD comes out
the other end. */
@@ -74,12 +72,11 @@ encrypt_decrypt(svn_crypto__ctx_t *ctx,
return SVN_NO_ERROR;
}
-#endif /* APU_HAVE_CRYPTO */
static svn_error_t *
test_encrypt_decrypt_password(apr_pool_t *pool)
{
-#if APU_HAVE_CRYPTO
+#ifdef SVN_HAVE_CRYPTO
svn_crypto__ctx_t *ctx;
const svn_string_t *master = svn_string_create("Pastor Massword", pool);
int i;
@@ -102,9 +99,9 @@ test_encrypt_decrypt_password(apr_pool_t
svn_pool_destroy(iterpool);
return SVN_NO_ERROR;
-#else
+#else /* SVN_HAVE_CRYPTO */
return svn_error_create(SVN_ERR_TEST_SKIPPED, NULL, NULL);
-#endif /* APU_HAVE_CRYPTO */
+#endif /* SVN_HAVE_CRYPTO */
}