You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by pq...@apache.org on 2009/03/14 22:27:09 UTC
svn commit: r754526 - in /labs/orthrus/trunk: include/private/context.h
src/hex.c
Author: pquerna
Date: Sat Mar 14 21:27:07 2009
New Revision: 754526
URL: http://svn.apache.org/viewvc?rev=754526&view=rev
Log:
Add function to decode a hex string into a uint64_t.
Modified:
labs/orthrus/trunk/include/private/context.h
labs/orthrus/trunk/src/hex.c
Modified: labs/orthrus/trunk/include/private/context.h
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/include/private/context.h?rev=754526&r1=754525&r2=754526&view=diff
==============================================================================
--- labs/orthrus/trunk/include/private/context.h (original)
+++ labs/orthrus/trunk/include/private/context.h Sat Mar 14 21:27:07 2009
@@ -56,8 +56,9 @@
orthrus_error_t* orthrus__alg_sha1_cycle(apr_uint64_t sequence,
orthrus_response_t *reply);
-
+
void orthrus__format_hex(orthrus_response_t *reply, apr_pool_t *pool);
+void orthrus__decode_hex(const char *input, apr_uint64_t *output);
void orthrus__format_words(orthrus_response_t *reply, apr_pool_t *pool);
struct orthrus_response_t {
Modified: labs/orthrus/trunk/src/hex.c
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/src/hex.c?rev=754526&r1=754525&r2=754526&view=diff
==============================================================================
--- labs/orthrus/trunk/src/hex.c (original)
+++ labs/orthrus/trunk/src/hex.c Sat Mar 14 21:27:07 2009
@@ -18,6 +18,30 @@
#include "private/context.h"
#include "apr_strings.h"
+/* inverse of APR_UINT64_T_HEX_FMT */
+void orthrus__decode_hex(const char *input, apr_uint64_t *output) {
+
+ *output = 0;
+ const char *p = input;
+ apr_uint64_t v = 0;
+
+ while (*p) {
+ char ch = *p;
+ if (ch >= '0' && ch <= '9') {
+ v = (v << 4) + (ch - '0');
+ }
+ else if (ch >= 'A' && ch <= 'F') {
+ v = (v << 4) + (ch - 'A' + 10);
+ }
+ else if (ch >= 'a' && ch <= 'f') {
+ v = (v << 4) + (ch - 'a' + 10);
+ }
+ p++;
+ }
+
+ *output = v;
+};
+
void orthrus__format_hex(orthrus_response_t *reply, apr_pool_t *pool)
{
int i;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org