Refactor "str.h": rename parameters 'dstlen' to 'dstsiz'

This commit is contained in:
Andrew Bettison 2015-08-17 19:43:58 +09:30
parent 586c6b3060
commit e73d50b48a
2 changed files with 14 additions and 14 deletions

16
str.c
View File

@ -60,11 +60,11 @@ int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t nbinary)
return -1; return -1;
} }
size_t strn_fromhex(unsigned char *dstBinary, ssize_t dstlen, const char *srcHex, const char **afterHex) size_t strn_fromhex(unsigned char *dstBinary, ssize_t dstsiz, const char *srcHex, const char **afterHex)
{ {
unsigned char *dstorig = dstBinary; unsigned char *dstorig = dstBinary;
unsigned char *dstend = dstBinary + dstlen; unsigned char *dstend = dstBinary + dstsiz;
while (dstlen == -1 || dstBinary < dstend) { while (dstsiz == -1 || dstBinary < dstend) {
int high = hexvalue(srcHex[0]); int high = hexvalue(srcHex[0]);
if (high == -1) if (high == -1)
break; break;
@ -988,14 +988,14 @@ size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t
return dst - odst; return dst - odst;
} }
void str_digest_passphrase(unsigned char *dstBinary, size_t dstlen, const char *passphrase) void str_digest_passphrase(unsigned char *dstBinary, size_t dstsiz, const char *passphrase)
{ {
return strn_digest_passphrase(dstBinary, dstlen, passphrase, strlen(passphrase)); return strn_digest_passphrase(dstBinary, dstsiz, passphrase, strlen(passphrase));
} }
void strn_digest_passphrase(unsigned char *dstBinary, size_t dstlen, const char *passphrase, size_t passlen) void strn_digest_passphrase(unsigned char *dstBinary, size_t dstsiz, const char *passphrase, size_t passlen)
{ {
assert(dstlen <= SERVAL_PASSPHRASE_DIGEST_MAX_BINARY); assert(dstsiz <= SERVAL_PASSPHRASE_DIGEST_MAX_BINARY);
SHA512_CTX context; SHA512_CTX context;
static const char salt1[] = "Sago pudding"; static const char salt1[] = "Sago pudding";
static const char salt2[] = "Rhubarb pie"; static const char salt2[] = "Rhubarb pie";
@ -1003,7 +1003,7 @@ void strn_digest_passphrase(unsigned char *dstBinary, size_t dstlen, const char
SHA512_Update(&context, (unsigned char *)salt1, sizeof salt1 - 1); SHA512_Update(&context, (unsigned char *)salt1, sizeof salt1 - 1);
SHA512_Update(&context, (unsigned char *)passphrase, passlen); SHA512_Update(&context, (unsigned char *)passphrase, passlen);
SHA512_Update(&context, (unsigned char *)salt2, sizeof salt2 - 1); SHA512_Update(&context, (unsigned char *)salt2, sizeof salt2 - 1);
SHA512_Final_Len(dstBinary, dstlen, &context); SHA512_Final_Len(dstBinary, dstsiz, &context);
} }
/* Return true if the string resembles a URI. /* Return true if the string resembles a URI.

12
str.h
View File

@ -126,7 +126,7 @@ int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t nbinary);
* *
* @author Andrew Bettison <andrew@servalproject.com> * @author Andrew Bettison <andrew@servalproject.com>
*/ */
size_t strn_fromhex(unsigned char *dstBinary, ssize_t dstlen, const char *src, const char **afterp); size_t strn_fromhex(unsigned char *dstBinary, ssize_t dstsiz, const char *src, const char **afterp);
/* -------------------- Base64 encoding and decoding -------------------- */ /* -------------------- Base64 encoding and decoding -------------------- */
@ -286,7 +286,7 @@ __SERVAL_DNA__STR_INLINE int hexvalue(char c) {
/* -------------------- In-line string formatting -------------------- */ /* -------------------- In-line string formatting -------------------- */
size_t sprintf_len(const char *fmt, ...); size_t sprintf_len(const char *fmt, ...);
#define alloca_sprintf(dstlen, fmt,...) strbuf_str(strbuf_sprintf(strbuf_alloca((dstlen) == -1 ? sprintf_len((fmt), ##__VA_ARGS__) + 1 : (size_t)(dstlen)), (fmt), ##__VA_ARGS__)) #define alloca_sprintf(dstsiz, fmt,...) strbuf_str(strbuf_sprintf(strbuf_alloca((dstsiz) == -1 ? sprintf_len((fmt), ##__VA_ARGS__) + 1 : (size_t)(dstsiz)), (fmt), ##__VA_ARGS__))
/* -------------------- Printable string representation -------------------- */ /* -------------------- Printable string representation -------------------- */
@ -296,8 +296,8 @@ size_t toprint_len(const char *srcBuf, size_t srcBytes, const char quotes[2]);
size_t toprint_str_len(const char *srcStr, const char quotes[2]); size_t toprint_str_len(const char *srcStr, const char quotes[2]);
size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t srclen, char endquote, const char **afterp); size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t srclen, char endquote, const char **afterp);
#define alloca_toprint_quoted(dstlen,buf,len,quotes) toprint((char *)alloca((dstlen) == -1 ? toprint_len((const char *)(buf),(len), (quotes)) + 1 : (size_t)(dstlen)), (size_t)(dstlen), (const char *)(buf), (len), (quotes)) #define alloca_toprint_quoted(dstsiz,buf,len,quotes) toprint((char *)alloca((dstsiz) == -1 ? toprint_len((const char *)(buf),(len), (quotes)) + 1 : (size_t)(dstsiz)), (size_t)(dstsiz), (const char *)(buf), (len), (quotes))
#define alloca_toprint(dstlen,buf,len) alloca_toprint_quoted(dstlen,buf,len,"``") #define alloca_toprint(dstsiz,buf,len) alloca_toprint_quoted(dstsiz,buf,len,"``")
#define alloca_str_toprint_quoted(str, quotes) toprint_str((char *)alloca(toprint_str_len((str), (quotes)) + 1), -1, (str), (quotes)) #define alloca_str_toprint_quoted(str, quotes) toprint_str((char *)alloca(toprint_str_len((str), (quotes)) + 1), -1, (str), (quotes))
#define alloca_str_toprint(str) alloca_str_toprint_quoted(str, "``") #define alloca_str_toprint(str) alloca_str_toprint_quoted(str, "``")
@ -311,8 +311,8 @@ size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t
* *
* @author Andrew Bettison <andrew@servalproject.com> * @author Andrew Bettison <andrew@servalproject.com>
*/ */
void str_digest_passphrase(unsigned char *dstBinary, size_t dstlen, const char *passphrase); void str_digest_passphrase(unsigned char *dstBinary, size_t dstsiz, const char *passphrase);
void strn_digest_passphrase(unsigned char *dstBinary, size_t dstlen, const char *passphrase, size_t passlen); void strn_digest_passphrase(unsigned char *dstBinary, size_t dstsiz, const char *passphrase, size_t passlen);
/* -------------------- Useful string primitives -------------------- */ /* -------------------- Useful string primitives -------------------- */