iodine 0.4.19 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of iodine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +22 -0
- data/LIMITS.md +19 -9
- data/README.md +92 -77
- data/SPEC-PubSub-Draft.md +113 -0
- data/SPEC-Websocket-Draft.md +127 -143
- data/bin/http-hello +0 -1
- data/bin/raw-rbhttp +1 -1
- data/bin/raw_broadcast +8 -10
- data/bin/updated api +2 -2
- data/bin/ws-broadcast +2 -4
- data/bin/ws-echo +2 -2
- data/examples/config.ru +13 -13
- data/examples/echo.ru +5 -6
- data/examples/hello.ru +2 -3
- data/examples/info.md +316 -0
- data/examples/pubsub_engine.ru +81 -0
- data/examples/redis.ru +9 -9
- data/examples/shootout.ru +45 -11
- data/ext/iodine/defer.c +194 -297
- data/ext/iodine/defer.h +61 -53
- data/ext/iodine/evio.c +0 -260
- data/ext/iodine/evio.h +50 -22
- data/ext/iodine/evio_callbacks.c +26 -0
- data/ext/iodine/evio_epoll.c +251 -0
- data/ext/iodine/evio_kqueue.c +193 -0
- data/ext/iodine/extconf.rb +1 -1
- data/ext/iodine/facil.c +1420 -542
- data/ext/iodine/facil.h +151 -64
- data/ext/iodine/fio_ary.h +418 -0
- data/ext/iodine/{base64.c → fio_base64.c} +33 -24
- data/ext/iodine/{base64.h → fio_base64.h} +6 -7
- data/ext/iodine/{fio_cli_helper.c → fio_cli.c} +77 -58
- data/ext/iodine/{fio_cli_helper.h → fio_cli.h} +9 -4
- data/ext/iodine/fio_hashmap.h +759 -0
- data/ext/iodine/fio_json_parser.h +651 -0
- data/ext/iodine/fio_llist.h +257 -0
- data/ext/iodine/fio_mem.c +672 -0
- data/ext/iodine/fio_mem.h +140 -0
- data/ext/iodine/fio_random.c +248 -0
- data/ext/iodine/{random.h → fio_random.h} +11 -14
- data/ext/iodine/{sha1.c → fio_sha1.c} +28 -24
- data/ext/iodine/{sha1.h → fio_sha1.h} +38 -16
- data/ext/iodine/{sha2.c → fio_sha2.c} +66 -49
- data/ext/iodine/{sha2.h → fio_sha2.h} +57 -26
- data/ext/iodine/{fiobj_internal.c → fio_siphash.c} +9 -90
- data/ext/iodine/fio_siphash.h +18 -0
- data/ext/iodine/fio_tmpfile.h +38 -0
- data/ext/iodine/fiobj.h +24 -7
- data/ext/iodine/fiobj4sock.h +23 -0
- data/ext/iodine/fiobj_ary.c +143 -226
- data/ext/iodine/fiobj_ary.h +17 -16
- data/ext/iodine/fiobj_data.c +1160 -0
- data/ext/iodine/fiobj_data.h +164 -0
- data/ext/iodine/fiobj_hash.c +298 -406
- data/ext/iodine/fiobj_hash.h +101 -54
- data/ext/iodine/fiobj_json.c +478 -601
- data/ext/iodine/fiobj_json.h +34 -9
- data/ext/iodine/fiobj_numbers.c +383 -51
- data/ext/iodine/fiobj_numbers.h +87 -11
- data/ext/iodine/fiobj_str.c +423 -184
- data/ext/iodine/fiobj_str.h +81 -32
- data/ext/iodine/fiobject.c +273 -522
- data/ext/iodine/fiobject.h +477 -112
- data/ext/iodine/http.c +2243 -83
- data/ext/iodine/http.h +842 -121
- data/ext/iodine/http1.c +810 -385
- data/ext/iodine/http1.h +16 -39
- data/ext/iodine/http1_parser.c +146 -74
- data/ext/iodine/http1_parser.h +15 -4
- data/ext/iodine/http_internal.c +1258 -0
- data/ext/iodine/http_internal.h +226 -0
- data/ext/iodine/http_mime_parser.h +341 -0
- data/ext/iodine/iodine.c +86 -68
- data/ext/iodine/iodine.h +26 -11
- data/ext/iodine/iodine_helpers.c +8 -7
- data/ext/iodine/iodine_http.c +487 -324
- data/ext/iodine/iodine_json.c +304 -0
- data/ext/iodine/iodine_json.h +6 -0
- data/ext/iodine/iodine_protocol.c +107 -45
- data/ext/iodine/iodine_pubsub.c +526 -225
- data/ext/iodine/iodine_pubsub.h +10 -0
- data/ext/iodine/iodine_websockets.c +268 -510
- data/ext/iodine/iodine_websockets.h +2 -4
- data/ext/iodine/pubsub.c +726 -432
- data/ext/iodine/pubsub.h +85 -103
- data/ext/iodine/rb-call.c +4 -4
- data/ext/iodine/rb-defer.c +46 -22
- data/ext/iodine/rb-fiobj2rb.h +117 -0
- data/ext/iodine/rb-rack-io.c +73 -238
- data/ext/iodine/rb-rack-io.h +2 -2
- data/ext/iodine/rb-registry.c +35 -93
- data/ext/iodine/rb-registry.h +1 -0
- data/ext/iodine/redis_engine.c +742 -304
- data/ext/iodine/redis_engine.h +42 -39
- data/ext/iodine/resp_parser.h +311 -0
- data/ext/iodine/sock.c +627 -490
- data/ext/iodine/sock.h +345 -297
- data/ext/iodine/spnlock.inc +15 -4
- data/ext/iodine/websocket_parser.h +16 -20
- data/ext/iodine/websockets.c +188 -257
- data/ext/iodine/websockets.h +24 -133
- data/lib/iodine.rb +52 -7
- data/lib/iodine/cli.rb +6 -24
- data/lib/iodine/json.rb +40 -0
- data/lib/iodine/version.rb +1 -1
- data/lib/iodine/websocket.rb +5 -3
- data/lib/rack/handler/iodine.rb +58 -13
- metadata +38 -48
- data/bin/ws-shootout +0 -107
- data/examples/broadcast.ru +0 -56
- data/ext/iodine/bscrypt-common.h +0 -116
- data/ext/iodine/bscrypt.h +0 -49
- data/ext/iodine/fio2resp.c +0 -60
- data/ext/iodine/fio2resp.h +0 -51
- data/ext/iodine/fio_dict.c +0 -446
- data/ext/iodine/fio_dict.h +0 -99
- data/ext/iodine/fio_hash_table.h +0 -370
- data/ext/iodine/fio_list.h +0 -111
- data/ext/iodine/fiobj_internal.h +0 -280
- data/ext/iodine/fiobj_primitives.c +0 -131
- data/ext/iodine/fiobj_primitives.h +0 -55
- data/ext/iodine/fiobj_sym.c +0 -135
- data/ext/iodine/fiobj_sym.h +0 -60
- data/ext/iodine/hex.c +0 -124
- data/ext/iodine/hex.h +0 -70
- data/ext/iodine/http1_request.c +0 -81
- data/ext/iodine/http1_request.h +0 -58
- data/ext/iodine/http1_response.c +0 -417
- data/ext/iodine/http1_response.h +0 -95
- data/ext/iodine/http_request.c +0 -111
- data/ext/iodine/http_request.h +0 -102
- data/ext/iodine/http_response.c +0 -1703
- data/ext/iodine/http_response.h +0 -250
- data/ext/iodine/misc.c +0 -182
- data/ext/iodine/misc.h +0 -74
- data/ext/iodine/random.c +0 -208
- data/ext/iodine/redis_connection.c +0 -278
- data/ext/iodine/redis_connection.h +0 -86
- data/ext/iodine/resp.c +0 -842
- data/ext/iodine/resp.h +0 -261
- data/ext/iodine/siphash.c +0 -154
- data/ext/iodine/siphash.h +0 -22
- data/ext/iodine/xor-crypt.c +0 -193
- data/ext/iodine/xor-crypt.h +0 -107
@@ -1,55 +0,0 @@
|
|
1
|
-
#ifndef FIOBJ_PRIMITIVES_H
|
2
|
-
/*
|
3
|
-
Copyright: Boaz Segev, 2017
|
4
|
-
License: MIT
|
5
|
-
*/
|
6
|
-
|
7
|
-
/**
|
8
|
-
Herein are defined some primitive types for the facil.io dynamic object system.
|
9
|
-
*/
|
10
|
-
#define FIOBJ_PRIMITIVES_H
|
11
|
-
|
12
|
-
#include "fiobject.h"
|
13
|
-
|
14
|
-
#ifdef __cplusplus
|
15
|
-
extern "C" {
|
16
|
-
#endif
|
17
|
-
|
18
|
-
/* *****************************************************************************
|
19
|
-
NULL
|
20
|
-
***************************************************************************** */
|
21
|
-
|
22
|
-
/** Identifies the NULL type. */
|
23
|
-
extern const uintptr_t FIOBJ_T_NULL;
|
24
|
-
|
25
|
-
/** Returns a NULL object. */
|
26
|
-
fiobj_s *fiobj_null(void);
|
27
|
-
|
28
|
-
/** Tests if a `fiobj_s *` is NULL. */
|
29
|
-
#define FIOBJ_IS_NULL(o) ((o) == NULL) || ((fiobj_s *)(o)->type == FIOBJ_T_NULL)
|
30
|
-
|
31
|
-
/* *****************************************************************************
|
32
|
-
True
|
33
|
-
***************************************************************************** */
|
34
|
-
|
35
|
-
/** Identifies the TRUE type. */
|
36
|
-
extern const uintptr_t FIOBJ_T_TRUE;
|
37
|
-
|
38
|
-
/** Returns a TRUE object. */
|
39
|
-
fiobj_s *fiobj_true(void);
|
40
|
-
|
41
|
-
/* *****************************************************************************
|
42
|
-
False
|
43
|
-
***************************************************************************** */
|
44
|
-
|
45
|
-
/** Identifies the FALSE type. */
|
46
|
-
extern const uintptr_t FIOBJ_T_FALSE;
|
47
|
-
|
48
|
-
/** Returns a FALSE object. */
|
49
|
-
fiobj_s *fiobj_false(void);
|
50
|
-
|
51
|
-
#ifdef __cplusplus
|
52
|
-
} /* extern "C" */
|
53
|
-
#endif
|
54
|
-
|
55
|
-
#endif
|
data/ext/iodine/fiobj_sym.c
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz segev, 2017
|
3
|
-
License: MIT
|
4
|
-
|
5
|
-
Feel free to copy, use and enjoy according to the license provided.
|
6
|
-
*/
|
7
|
-
|
8
|
-
#include "fiobj_internal.h"
|
9
|
-
|
10
|
-
/* *****************************************************************************
|
11
|
-
Symbol Type
|
12
|
-
***************************************************************************** */
|
13
|
-
|
14
|
-
typedef struct {
|
15
|
-
struct fiobj_vtable_s *vtable;
|
16
|
-
uintptr_t hash;
|
17
|
-
uint64_t len;
|
18
|
-
char str[];
|
19
|
-
} fiobj_sym_s;
|
20
|
-
|
21
|
-
#define obj2sym(o) ((fiobj_sym_s *)(o))
|
22
|
-
|
23
|
-
/* *****************************************************************************
|
24
|
-
Symbol VTable
|
25
|
-
***************************************************************************** */
|
26
|
-
|
27
|
-
static int fiobj_sym_is_eq(const fiobj_s *self, const fiobj_s *other) {
|
28
|
-
if (other->type != self->type)
|
29
|
-
return 0;
|
30
|
-
return obj2sym(self)->hash == obj2sym(other)->hash;
|
31
|
-
}
|
32
|
-
|
33
|
-
static fio_cstr_s fio_sym2str(const fiobj_s *o) {
|
34
|
-
return (fio_cstr_s){.buffer = obj2sym(o)->str, .len = obj2sym(o)->len};
|
35
|
-
}
|
36
|
-
static int64_t fio_sym2i(const fiobj_s *o) {
|
37
|
-
char *s = obj2sym(o)->str;
|
38
|
-
return fio_atol(&s);
|
39
|
-
}
|
40
|
-
static double fio_sym2f(const fiobj_s *o) {
|
41
|
-
char *s = obj2sym(o)->str;
|
42
|
-
return fio_atof(&s);
|
43
|
-
}
|
44
|
-
|
45
|
-
static struct fiobj_vtable_s FIOBJ_VTABLE_SYMBOL = {
|
46
|
-
.name = "Symbol",
|
47
|
-
.free = fiobj_simple_dealloc,
|
48
|
-
.to_i = fio_sym2i,
|
49
|
-
.to_f = fio_sym2f,
|
50
|
-
.to_str = fio_sym2str,
|
51
|
-
.is_eq = fiobj_sym_is_eq,
|
52
|
-
.is_true = fiobj_noop_true,
|
53
|
-
.count = fiobj_noop_count,
|
54
|
-
.unwrap = fiobj_noop_unwrap,
|
55
|
-
.each1 = fiobj_noop_each1,
|
56
|
-
};
|
57
|
-
|
58
|
-
const uintptr_t FIOBJ_T_SYMBOL = (uintptr_t)(&FIOBJ_VTABLE_SYMBOL);
|
59
|
-
|
60
|
-
/* *****************************************************************************
|
61
|
-
Symbol API
|
62
|
-
***************************************************************************** */
|
63
|
-
|
64
|
-
static inline fiobj_s *fiobj_sym_alloc(size_t len) {
|
65
|
-
fiobj_s *o = fiobj_alloc(sizeof(fiobj_sym_s) + len + 1);
|
66
|
-
if (!o)
|
67
|
-
perror("ERROR: fiobj symbol couldn't allocate memory"), exit(errno);
|
68
|
-
*obj2sym(o) = (fiobj_sym_s){
|
69
|
-
.vtable = &FIOBJ_VTABLE_SYMBOL, .len = len,
|
70
|
-
};
|
71
|
-
return o;
|
72
|
-
}
|
73
|
-
|
74
|
-
/** Creates a Symbol object. Use `fiobj_free`. */
|
75
|
-
fiobj_s *fiobj_sym_new(const char *str, size_t len) {
|
76
|
-
fiobj_s *s = fiobj_sym_alloc(len);
|
77
|
-
if (str)
|
78
|
-
memcpy(obj2sym(s)->str, str, len);
|
79
|
-
obj2sym(s)->str[len] = 0;
|
80
|
-
obj2sym(s)->hash = (uintptr_t)fiobj_sym_hash(str, len);
|
81
|
-
return s;
|
82
|
-
}
|
83
|
-
|
84
|
-
/** Finalizes a pre-allocated Symbol buffer to set it's final length and
|
85
|
-
* calculate it's final hashing value. */
|
86
|
-
fiobj_s *fiobj_sym_reinitialize(fiobj_s *s, const size_t len) {
|
87
|
-
if (obj2sym(s)->len < len)
|
88
|
-
fprintf(stderr,
|
89
|
-
"FATAL ERROR: facil.io Symbol object reinitialization error.\n"),
|
90
|
-
exit(-1);
|
91
|
-
obj2sym(s)->len = len;
|
92
|
-
obj2sym(s)->str[len] = 0;
|
93
|
-
obj2sym(s)->hash = (uintptr_t)fiobj_sym_hash(obj2sym(s)->str, len);
|
94
|
-
return s;
|
95
|
-
}
|
96
|
-
|
97
|
-
/** Creates a Symbol object using a printf like interface. */
|
98
|
-
__attribute__((format(printf, 1, 0))) fiobj_s *
|
99
|
-
fiobj_symvprintf(const char *format, va_list argv) {
|
100
|
-
fiobj_s *sym = NULL;
|
101
|
-
va_list argv_cpy;
|
102
|
-
va_copy(argv_cpy, argv);
|
103
|
-
int len = vsnprintf(NULL, 0, format, argv_cpy);
|
104
|
-
va_end(argv_cpy);
|
105
|
-
if (len <= 0) {
|
106
|
-
sym = fiobj_sym_alloc(0);
|
107
|
-
obj2sym(sym)->hash = fiobj_sym_hash(NULL, 0);
|
108
|
-
return sym;
|
109
|
-
}
|
110
|
-
sym = fiobj_sym_alloc(len); /* adds 1 to len, for NUL */
|
111
|
-
vsnprintf(obj2sym(sym)->str, len + 1, format, argv);
|
112
|
-
obj2sym(sym)->str[len] = 0; /* enforce NUL */
|
113
|
-
obj2sym(sym)->hash = (uintptr_t)fiobj_sym_hash(obj2sym(sym)->str, len);
|
114
|
-
return sym;
|
115
|
-
}
|
116
|
-
__attribute__((format(printf, 1, 2))) fiobj_s *
|
117
|
-
fiobj_symprintf(const char *format, ...) {
|
118
|
-
va_list argv;
|
119
|
-
va_start(argv, format);
|
120
|
-
fiobj_s *sym = fiobj_symvprintf(format, argv);
|
121
|
-
va_end(argv);
|
122
|
-
return sym;
|
123
|
-
}
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Returns a symbol's identifier.
|
127
|
-
*
|
128
|
-
* The unique identifier is calculated using SipHash and is equal for all Symbol
|
129
|
-
* objects that were created using the same data.
|
130
|
-
*/
|
131
|
-
uintptr_t fiobj_sym_id(fiobj_s *sym) {
|
132
|
-
if (sym->type != FIOBJ_T_SYMBOL)
|
133
|
-
return 0;
|
134
|
-
return obj2sym(sym)->hash;
|
135
|
-
}
|
data/ext/iodine/fiobj_sym.h
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
#ifndef H_FIOBJ_SYMBOL_H
|
2
|
-
/*
|
3
|
-
Copyright: Boaz Segev, 2017
|
4
|
-
License: MIT
|
5
|
-
*/
|
6
|
-
|
7
|
-
/**
|
8
|
-
*/
|
9
|
-
#define H_FIOBJ_SYMBOL_H
|
10
|
-
|
11
|
-
#include "fiobject.h"
|
12
|
-
|
13
|
-
#ifdef __cplusplus
|
14
|
-
extern "C" {
|
15
|
-
#endif
|
16
|
-
|
17
|
-
/** Symbol type identifier */
|
18
|
-
extern const uintptr_t FIOBJ_T_SYMBOL;
|
19
|
-
|
20
|
-
/* *****************************************************************************
|
21
|
-
Symbol API
|
22
|
-
***************************************************************************** */
|
23
|
-
|
24
|
-
/** Creates a Symbol object. Use `fiobj_free`. */
|
25
|
-
fiobj_s *fiobj_sym_new(const char *str, size_t len);
|
26
|
-
|
27
|
-
/** Creates a Symbol object using a printf like interface. */
|
28
|
-
__attribute__((format(printf, 1, 0))) fiobj_s *
|
29
|
-
fiobj_symvprintf(const char *format, va_list argv);
|
30
|
-
|
31
|
-
/** Creates a Symbol object using a printf like interface. */
|
32
|
-
__attribute__((format(printf, 1, 2))) fiobj_s *
|
33
|
-
fiobj_symprintf(const char *format, ...);
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Returns a symbol's identifier.
|
37
|
-
*
|
38
|
-
* The unique identifier is calculated using SipHash and is equal for all Symbol
|
39
|
-
* objects that were created using the same data.
|
40
|
-
*/
|
41
|
-
uintptr_t fiobj_sym_id(fiobj_s *sym);
|
42
|
-
|
43
|
-
/* *****************************************************************************
|
44
|
-
Risky Symbol API
|
45
|
-
***************************************************************************** */
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Reinitializes a pre-allocated Symbol buffer to set it's final length and
|
49
|
-
* calculate it's final hashing value.
|
50
|
-
*
|
51
|
-
* NEVER use this on a symbol that was already used in other objects, such as a
|
52
|
-
* Hash.
|
53
|
-
*/
|
54
|
-
fiobj_s *fiobj_sym_reinitialize(fiobj_s *s, const size_t len);
|
55
|
-
|
56
|
-
#ifdef __cplusplus
|
57
|
-
} /* extern "C" */
|
58
|
-
#endif
|
59
|
-
|
60
|
-
#endif
|
data/ext/iodine/hex.c
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz segev, 2016-2017
|
3
|
-
License: MIT except for any non-public-domain algorithms (none that I'm aware
|
4
|
-
of), which might be subject to their own licenses.
|
5
|
-
|
6
|
-
Feel free to copy, use and enjoy in accordance with to the license(s).
|
7
|
-
*/
|
8
|
-
#ifndef _GNU_SOURCE
|
9
|
-
#define _GNU_SOURCE
|
10
|
-
#endif
|
11
|
-
#include "hex.h"
|
12
|
-
#include <ctype.h>
|
13
|
-
|
14
|
-
/* ***************************************************************************
|
15
|
-
Hex Conversion
|
16
|
-
*/
|
17
|
-
|
18
|
-
/*
|
19
|
-
#define hex2i(h) \
|
20
|
-
(((h) >= '0' && (h) <= '9') ? ((h) - '0') : (((h) | 32) - 'a' + 10))
|
21
|
-
*/
|
22
|
-
|
23
|
-
#define i2hex(hi) (((hi) < 10) ? ('0' + (hi)) : ('A' + ((hi)-10)))
|
24
|
-
|
25
|
-
/* Credit to Jonathan Leffler for the idea */
|
26
|
-
#define hex2i(c) \
|
27
|
-
(((c) >= '0' && (c) <= '9') \
|
28
|
-
? ((c)-48) \
|
29
|
-
: (((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) \
|
30
|
-
? (((c) | 32) - 87) \
|
31
|
-
: ({ \
|
32
|
-
return -1; \
|
33
|
-
0; \
|
34
|
-
}))
|
35
|
-
|
36
|
-
/**
|
37
|
-
Returns 1 if the string is HEX encoded (no non-valid hex values). Returns 0 if
|
38
|
-
it isn't.
|
39
|
-
*/
|
40
|
-
int bscrypt_is_hex(const char *string, size_t length) {
|
41
|
-
// for (size_t i = 0; i < length; i++) {
|
42
|
-
// if (isxdigit(string[i]) == 0)
|
43
|
-
// return 0;
|
44
|
-
char c;
|
45
|
-
for (size_t i = 0; i < length; i++) {
|
46
|
-
c = string[i];
|
47
|
-
if ((!isspace(c)) &&
|
48
|
-
(c < '0' || c > 'z' ||
|
49
|
-
!((c >= 'a') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))))
|
50
|
-
return 0;
|
51
|
-
}
|
52
|
-
return 1;
|
53
|
-
}
|
54
|
-
/**
|
55
|
-
This will convert the string (byte stream) to a Hex string. This is not
|
56
|
-
cryptography, just conversion for pretty print.
|
57
|
-
|
58
|
-
The target buffer MUST have enough room for the expected data. The expected
|
59
|
-
data is double the length of the string + 1 byte for the NULL terminator
|
60
|
-
byte.
|
61
|
-
|
62
|
-
A NULL byte will be appended to the target buffer. The function will return
|
63
|
-
the number of bytes written to the target buffer.
|
64
|
-
|
65
|
-
Returns the number of bytes actually written to the target buffer (excluding
|
66
|
-
the NULL terminator byte).
|
67
|
-
*/
|
68
|
-
int bscrypt_str2hex(char *target, const char *string, size_t length) {
|
69
|
-
if (!target)
|
70
|
-
return -1;
|
71
|
-
size_t i = length;
|
72
|
-
target[(length << 1) + 1] = 0;
|
73
|
-
// go in reverse, so that target could be same as string.
|
74
|
-
while (i) {
|
75
|
-
--i;
|
76
|
-
target[(i << 1) + 1] = i2hex(string[i] & 0x0F);
|
77
|
-
target[(i << 1)] = i2hex(((uint8_t *)string)[i] >> 4);
|
78
|
-
}
|
79
|
-
return (length << 1);
|
80
|
-
}
|
81
|
-
|
82
|
-
/**
|
83
|
-
This will convert a Hex string to a byte string. This is not cryptography,
|
84
|
-
just conversion for pretty print.
|
85
|
-
|
86
|
-
The target buffer MUST have enough room for the expected data. The expected
|
87
|
-
data is half the length of the Hex string + 1 byte for the NULL terminator
|
88
|
-
byte.
|
89
|
-
|
90
|
-
A NULL byte will be appended to the target buffer. The function will return
|
91
|
-
the number of bytes written to the target buffer.
|
92
|
-
|
93
|
-
If the target buffer is NULL, the encoded string will be destructively
|
94
|
-
edited
|
95
|
-
and the decoded data will be placed in the original string's buffer.
|
96
|
-
|
97
|
-
Returns the number of bytes actually written to the target buffer (excluding
|
98
|
-
the NULL terminator byte).
|
99
|
-
*/
|
100
|
-
int bscrypt_hex2str(char *target, char *hex, size_t length) {
|
101
|
-
if (!target)
|
102
|
-
target = hex;
|
103
|
-
size_t i = 0;
|
104
|
-
size_t written = 0;
|
105
|
-
while (i + 1 < length) {
|
106
|
-
if (isspace(hex[i])) {
|
107
|
-
++i;
|
108
|
-
continue;
|
109
|
-
}
|
110
|
-
target[written] = (hex2i(hex[i]) << 4) | hex2i(hex[i + 1]);
|
111
|
-
++written;
|
112
|
-
i += 2;
|
113
|
-
}
|
114
|
-
if (i < length && !isspace(hex[i])) {
|
115
|
-
target[written] = hex2i(hex[i + 1]);
|
116
|
-
++written;
|
117
|
-
}
|
118
|
-
|
119
|
-
target[written] = 0;
|
120
|
-
return written;
|
121
|
-
}
|
122
|
-
|
123
|
-
#undef hex2i
|
124
|
-
#undef i2hex
|
data/ext/iodine/hex.h
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz segev, 2016-2017
|
3
|
-
License: MIT except for any non-public-domain algorithms (none that I'm aware
|
4
|
-
of), which might be subject to their own licenses.
|
5
|
-
|
6
|
-
Feel free to copy, use and enjoy in accordance with to the license(s).
|
7
|
-
*/
|
8
|
-
#ifndef bscrypt_HEX_H
|
9
|
-
#define bscrypt_HEX_H
|
10
|
-
#include "bscrypt-common.h"
|
11
|
-
/* *****************************************************************************
|
12
|
-
C++ extern
|
13
|
-
*/
|
14
|
-
#if defined(__cplusplus)
|
15
|
-
extern "C" {
|
16
|
-
#endif
|
17
|
-
|
18
|
-
/* ***************************************************************************
|
19
|
-
Hex Conversion
|
20
|
-
*/
|
21
|
-
|
22
|
-
/**
|
23
|
-
Returns 1 if the string is HEX encoded (no non-valid hex values). Returns 0 if
|
24
|
-
it isn't.
|
25
|
-
*/
|
26
|
-
int bscrypt_is_hex(const char *string, size_t length);
|
27
|
-
/**
|
28
|
-
This will convert the string (byte stream) to a Hex string. This is not
|
29
|
-
cryptography, just conversion for pretty print.
|
30
|
-
|
31
|
-
The target buffer MUST have enough room for the expected data. The expected
|
32
|
-
data is double the length of the string + 1 byte for the NULL terminator
|
33
|
-
byte.
|
34
|
-
|
35
|
-
A NULL byte will be appended to the target buffer. The function will return
|
36
|
-
the number of bytes written to the target buffer.
|
37
|
-
|
38
|
-
Returns the number of bytes actually written to the target buffer (excluding
|
39
|
-
the NULL terminator byte).
|
40
|
-
*/
|
41
|
-
int bscrypt_str2hex(char *target, const char *string, size_t length);
|
42
|
-
|
43
|
-
/**
|
44
|
-
This will convert a Hex string to a byte string. This is not cryptography,
|
45
|
-
just conversion for pretty print.
|
46
|
-
|
47
|
-
The target buffer MUST have enough room for the expected data. The expected
|
48
|
-
data is half the length of the Hex string + 1 byte for the NULL terminator
|
49
|
-
byte.
|
50
|
-
|
51
|
-
A NULL byte will be appended to the target buffer. The function will return
|
52
|
-
the number of bytes written to the target buffer.
|
53
|
-
|
54
|
-
If the target buffer is NULL, the encoded string will be destructively
|
55
|
-
edited
|
56
|
-
and the decoded data will be placed in the original string's buffer.
|
57
|
-
|
58
|
-
Returns the number of bytes actually written to the target buffer (excluding
|
59
|
-
the NULL terminator byte).
|
60
|
-
*/
|
61
|
-
int bscrypt_hex2str(char *target, char *hex, size_t length);
|
62
|
-
|
63
|
-
/* *****************************************************************************
|
64
|
-
C++ extern finish
|
65
|
-
*/
|
66
|
-
#if defined(__cplusplus)
|
67
|
-
}
|
68
|
-
#endif
|
69
|
-
|
70
|
-
#endif
|