mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 10:05:08 +00:00
encoding: simplify {places,eats}_dots
Why not using constant bools? Much simpler than complex function calls, that eventually return constant values. Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
0eb3b65158
commit
4591cafd27
@ -51,11 +51,6 @@ static const unsigned char cb128[] =
|
||||
static unsigned char rev128[256];
|
||||
static int reverse_init = 0;
|
||||
|
||||
static int base128_handles_dots(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline static void base128_reverse_init(void)
|
||||
{
|
||||
int i;
|
||||
@ -258,8 +253,8 @@ const struct encoder base128_ops = {
|
||||
.encode = base128_encode,
|
||||
.decode = base128_decode,
|
||||
|
||||
.places_dots = base128_handles_dots,
|
||||
.eats_dots = base128_handles_dots,
|
||||
.places_dots = false,
|
||||
.eats_dots = false,
|
||||
|
||||
.blocksize_raw = BASE128_BLKSIZE_RAW,
|
||||
.blocksize_encoded = BASE128_BLKSIZE_ENC,
|
||||
|
@ -32,11 +32,6 @@ static const char cb32_ucase[] =
|
||||
static unsigned char rev32[256];
|
||||
static int reverse_init = 0;
|
||||
|
||||
static int base32_handles_dots(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline static void base32_reverse_init(void)
|
||||
{
|
||||
int i;
|
||||
@ -235,8 +230,8 @@ const struct encoder base32_ops = {
|
||||
.encode = base32_encode,
|
||||
.decode = base32_decode,
|
||||
|
||||
.places_dots = base32_handles_dots,
|
||||
.eats_dots = base32_handles_dots,
|
||||
.places_dots = false,
|
||||
.eats_dots = false,
|
||||
|
||||
.blocksize_raw = BASE32_BLKSIZE_RAW,
|
||||
.blocksize_encoded = BASE32_BLKSIZE_ENC,
|
||||
|
@ -32,11 +32,6 @@ static const char cb64[] =
|
||||
static unsigned char rev64[256];
|
||||
static int reverse_init = 0;
|
||||
|
||||
static int base64_handles_dots(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline static void base64_reverse_init(void)
|
||||
{
|
||||
int i;
|
||||
@ -173,8 +168,8 @@ const struct encoder base64_ops = {
|
||||
.encode = base64_encode,
|
||||
.decode = base64_decode,
|
||||
|
||||
.places_dots = base64_handles_dots,
|
||||
.eats_dots = base64_handles_dots,
|
||||
.places_dots = false,
|
||||
.eats_dots = false,
|
||||
|
||||
.blocksize_raw = BASE64_BLKSIZE_RAW,
|
||||
.blocksize_encoded = BASE64_BLKSIZE_ENC,
|
||||
|
@ -29,14 +29,14 @@ int build_hostname(char *buf, size_t buflen, const char *data,
|
||||
space = MIN((size_t)maxlen, buflen) - strlen(topdomain) - 8;
|
||||
/* 8 = 5 max header length + 1 dot before topdomain + 2 safety */
|
||||
|
||||
if (!encoder->places_dots())
|
||||
if (!encoder->places_dots)
|
||||
space -= (space / 57); /* space for dots */
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
encoder->encode(buf, &space, data, datalen);
|
||||
|
||||
if (!encoder->places_dots())
|
||||
if (!encoder->places_dots)
|
||||
inline_dotify(buf, buflen);
|
||||
|
||||
b = buf;
|
||||
@ -57,7 +57,7 @@ int build_hostname(char *buf, size_t buflen, const char *data,
|
||||
int unpack_data(char *buf, size_t buflen, char *data, size_t datalen,
|
||||
const struct encoder *enc)
|
||||
{
|
||||
if (!enc->eats_dots())
|
||||
if (!enc->eats_dots)
|
||||
datalen = inline_undotify(data, datalen);
|
||||
return enc->decode(buf, &buflen, data, datalen);
|
||||
}
|
||||
|
@ -24,6 +24,8 @@
|
||||
#ifndef _ENCODING_H_
|
||||
#define _ENCODING_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* All-0, all-1, 01010101, 10101010: each 4 times to make sure the pattern
|
||||
spreads across multiple encoded chars -> 16 bytes total.
|
||||
Followed by 32 bytes from my /dev/random; should be enough.
|
||||
@ -36,8 +38,8 @@ struct encoder {
|
||||
int (*encode)(char *dst, size_t *dstlen, const void *src, size_t srclen);
|
||||
int (*decode)(void *dst, size_t *dstlen, const char *src, size_t srclen);
|
||||
|
||||
int (*places_dots)(void);
|
||||
int (*eats_dots)(void);
|
||||
const bool places_dots;
|
||||
const bool eats_dots;
|
||||
|
||||
const int blocksize_raw;
|
||||
const int blocksize_encoded;
|
||||
|
@ -2136,31 +2136,31 @@ write_dns_nameenc(char *buf, size_t buflen, const char *data, int datalen, char
|
||||
|
||||
if (downenc == 'S') {
|
||||
buf[0] = 'i';
|
||||
if (!base64_ops.places_dots())
|
||||
if (!base64_ops.places_dots)
|
||||
space -= (space / 57); /* space for dots */
|
||||
base64_ops.encode(buf+1, &space, data, datalen);
|
||||
if (!base64_ops.places_dots())
|
||||
if (!base64_ops.places_dots)
|
||||
inline_dotify(buf, buflen);
|
||||
} else if (downenc == 'U') {
|
||||
buf[0] = 'j';
|
||||
if (!base64u_ops.places_dots())
|
||||
if (!base64u_ops.places_dots)
|
||||
space -= (space / 57); /* space for dots */
|
||||
base64u_ops.encode(buf+1, &space, data, datalen);
|
||||
if (!base64u_ops.places_dots())
|
||||
if (!base64u_ops.places_dots)
|
||||
inline_dotify(buf, buflen);
|
||||
} else if (downenc == 'V') {
|
||||
buf[0] = 'k';
|
||||
if (!base128_ops.places_dots())
|
||||
if (!base128_ops.places_dots)
|
||||
space -= (space / 57); /* space for dots */
|
||||
base128_ops.encode(buf+1, &space, data, datalen);
|
||||
if (!base128_ops.places_dots())
|
||||
if (!base128_ops.places_dots)
|
||||
inline_dotify(buf, buflen);
|
||||
} else {
|
||||
buf[0] = 'h';
|
||||
if (!base32_ops.places_dots())
|
||||
if (!base32_ops.places_dots)
|
||||
space -= (space / 57); /* space for dots */
|
||||
base32_ops.encode(buf+1, &space, data, datalen);
|
||||
if (!base32_ops.places_dots())
|
||||
if (!base32_ops.places_dots)
|
||||
inline_dotify(buf, buflen);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user