Skip to content

Commit

Permalink
re-format code
Browse files Browse the repository at this point in the history
  • Loading branch information
xrdavies committed Jun 27, 2018
1 parent 3c646a5 commit 0da85d6
Show file tree
Hide file tree
Showing 61 changed files with 6,628 additions and 6,369 deletions.
138 changes: 69 additions & 69 deletions client/address.c
@@ -1,69 +1,69 @@
/* addresses, T13.692-T13.720 $DVS:time$ */

#include <stdint.h>
#include <string.h>
#include "address.h"

static const uint8_t bits2mime[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t mime2bits[256];

// intializes the address module
int xdag_address_init(void)
{
int i;

memset(mime2bits, 0xFF, 256);

for (i = 0; i < 64; ++i) {
mime2bits[bits2mime[i]] = i;
}

return 0;
}

// converts address to hash
int xdag_address2hash(const char *address, xdag_hash_t hash)
{
uint8_t *fld = (uint8_t*)hash;
int i, c, d, n;

for (int e = n = i = 0; i < 32; ++i) {
do {
if (!(c = (uint8_t)*address++))
return -1;
d = mime2bits[c];
} while (d & 0xC0);
e <<= 6;
e |= d;
n += 6;

if (n >= 8) {
n -= 8;
*fld++ = e >> n;
}
}

for (i = 0; i < 8; ++i) {
*fld++ = 0;
}

return 0;
}

// converts hash to address
void xdag_hash2address(const xdag_hash_t hash, char *address)
{
int c, d;
const uint8_t *fld = (const uint8_t*)hash;

for (int i = c = d = 0; i < 32; ++i) {
if (d < 6) {
d += 8;
c <<= 8;
c |= *fld++;
}
d -= 6;
*address++ = bits2mime[c >> d & 0x3F];
}
*address = 0;
}
/* addresses, T13.692-T13.720 $DVS:time$ */

#include <stdint.h>
#include <string.h>
#include "address.h"

static const uint8_t bits2mime[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t mime2bits[256];

// intializes the address module
int xdag_address_init(void)
{
int i;

memset(mime2bits, 0xFF, 256);

for (i = 0; i < 64; ++i) {
mime2bits[bits2mime[i]] = i;
}

return 0;
}

// converts address to hash
int xdag_address2hash(const char *address, xdag_hash_t hash)
{
uint8_t *fld = (uint8_t*)hash;
int i, c, d, n;

for (int e = n = i = 0; i < 32; ++i) {
do {
if (!(c = (uint8_t)*address++))
return -1;
d = mime2bits[c];
} while (d & 0xC0);
e <<= 6;
e |= d;
n += 6;

if (n >= 8) {
n -= 8;
*fld++ = e >> n;
}
}

for (i = 0; i < 8; ++i) {
*fld++ = 0;
}

return 0;
}

// converts hash to address
void xdag_hash2address(const xdag_hash_t hash, char *address)
{
int c, d;
const uint8_t *fld = (const uint8_t*)hash;

for (int i = c = d = 0; i < 32; ++i) {
if (d < 6) {
d += 8;
c <<= 8;
c |= *fld++;
}
d -= 6;
*address++ = bits2mime[c >> d & 0x3F];
}
*address = 0;
}
8 changes: 8 additions & 0 deletions client/address.h
Expand Up @@ -5,6 +5,10 @@

#include "hash.h"

#ifdef __cplusplus
extern "C" {
#endif

/* intializes the addresses module */
extern int xdag_address_init(void);

Expand All @@ -13,5 +17,9 @@ extern int xdag_address2hash(const char *address, xdag_hash_t hash);

/* converts hash to address */
extern void xdag_hash2address(const xdag_hash_t hash, char *address);

#ifdef __cplusplus
};
#endif

#endif

0 comments on commit 0da85d6

Please sign in to comment.