Permalink
Browse files

Make the MD5 library C compatible

  • Loading branch information...
1 parent ff3ec91 commit 4934f3cfb8a4b501749d9c2f68a5750d0022d797 @FooBarWidget FooBarWidget committed May 7, 2013
Showing with 32 additions and 24 deletions.
  1. +19 −16 ext/common/Utils/MD5.cpp
  2. +13 −8 ext/common/Utils/MD5.h
View
@@ -52,11 +52,12 @@
*/
#include "MD5.h"
-#include <string.h>
-#include <boost/detail/endian.hpp>
-#include "StrIntUtils.h"
-
-namespace Passenger {
+#include "../../boost/detail/endian.hpp" /* File is C compatible. */
+#ifdef __cplusplus
+ #include <string.h>
+ #include "StrIntUtils.h"
+ namespace Passenger {
+#endif
#if defined(BOOST_BIG_ENDIAN)
# define ARCH_IS_BIG_ENDIAN 1
@@ -390,17 +391,19 @@ md5_finish(md5_state_t *pms, md5_byte_t digest[16])
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}
-std::string
-md5_hex(const StaticString &input)
-{
- md5_state_t pms;
- md5_byte_t digest[16];
+#ifdef __cplusplus
+ std::string
+ md5_hex(const StaticString &input)
+ {
+ md5_state_t pms;
+ md5_byte_t digest[16];
- md5_init(&pms);
- md5_append(&pms, (const md5_byte_t *) input.data(), input.size());
- md5_finish(&pms, digest);
+ md5_init(&pms);
+ md5_append(&pms, (const md5_byte_t *) input.data(), input.size());
+ md5_finish(&pms, digest);
- return toHex(StaticString((const char *) digest, 16));
-}
+ return toHex(StaticString((const char *) digest, 16));
+ }
-} // namespace Passenger
+ } // namespace Passenger
+#endif
View
@@ -50,9 +50,14 @@
#ifndef _PASSENGER_MD5_H_
#define _PASSENGER_MD5_H_
-#include <string>
-#include <boost/cstdint.hpp>
-#include "../StaticString.h"
+#ifdef __cplusplus
+ #include "../../boost/cstdint.hpp"
+ #include <string>
+ #include <StaticString.h>
+ namespace Passenger {
+#else
+ #include <stdint.h>
+#endif
/*
* This package supports both compile-time and run-time determination of CPU
@@ -64,8 +69,6 @@
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/
-namespace Passenger {
-
typedef uint8_t md5_byte_t; /* 8-bit byte */
typedef uint32_t md5_word_t; /* 32-bit word */
@@ -90,9 +93,11 @@ void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
/* Finish the message and return the digest. */
void md5_finish(md5_state_t *pms, md5_byte_t digest[MD5_SIZE]);
-/* Convenience method for directly converting data into a hexadecimal MD5 string. */
-std::string md5_hex(const StaticString &input);
+#ifdef __cplusplus
+ /* Convenience method for directly converting data into a hexadecimal MD5 string. */
+ std::string md5_hex(const StaticString &input);
-} // namespace Passenger
+ } // namespace Passenger
+#endif
#endif /* _PASSENGER_MD5_H_ */

0 comments on commit 4934f3c

Please sign in to comment.