From 72687e5edb3efaf3810cfb37964094d8a156ae86 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 6 Jan 2017 10:42:07 +0100 Subject: [PATCH] Bug 1300109 - Move SECU_HexString2SECItem to basicutil.c, r=franziskus Also add the stub declaration in basicutil.h, and remove unnecesary #include for secutil.h in some files. --HG-- extra : histedit_source : 68a77d7e83c310fbe880daac11323dfaa71a5f4a --- cmd/ecperf/ecperf.c | 3 ++- cmd/fbectest/fbectest.c | 1 - cmd/lib/basicutil.c | 43 +++++++++++++++++++++++++++++++++++++++++ cmd/lib/basicutil.h | 6 ++++++ cmd/lib/secutil.c | 43 ----------------------------------------- 5 files changed, 51 insertions(+), 45 deletions(-) diff --git a/cmd/ecperf/ecperf.c b/cmd/ecperf/ecperf.c index 5108c99b86..41ecbdc609 100644 --- a/cmd/ecperf/ecperf.c +++ b/cmd/ecperf/ecperf.c @@ -9,7 +9,6 @@ #include "basicutil.h" #include "pkcs11.h" #include "nspr.h" -#include "secutil.h" #include #define __PASTE(x, y) x##y @@ -106,6 +105,8 @@ typedef struct ThreadDataStr { int isSign; } ThreadData; +typedef SECItem SECKEYECParams; + void PKCS11Thread(void *data) { diff --git a/cmd/fbectest/fbectest.c b/cmd/fbectest/fbectest.c index 4e2be00eb0..18f0b73700 100644 --- a/cmd/fbectest/fbectest.c +++ b/cmd/fbectest/fbectest.c @@ -9,7 +9,6 @@ #include "basicutil.h" #include "secder.h" #include "secitem.h" -#include "secutil.h" #include "nspr.h" #include diff --git a/cmd/lib/basicutil.c b/cmd/lib/basicutil.c index 49789bc29b..8b491d7cf4 100644 --- a/cmd/lib/basicutil.c +++ b/cmd/lib/basicutil.c @@ -731,3 +731,46 @@ SECU_SECItemHexStringToBinary(SECItem *srcdest) srcdest->len /= 2; return SECSuccess; } + +SECItem * +SECU_HexString2SECItem(PLArenaPool *arena, SECItem *item, const char *str) +{ + int i = 0; + int byteval = 0; + int tmp = PORT_Strlen(str); + + PORT_Assert(arena); + PORT_Assert(item); + + if ((tmp % 2) != 0) { + PORT_SetError(SEC_ERROR_INVALID_ARGS); + return NULL; + } + + item = SECITEM_AllocItem(arena, item, tmp / 2); + if (item == NULL) { + return NULL; + } + + while (str[i]) { + if ((str[i] >= '0') && (str[i] <= '9')) { + tmp = str[i] - '0'; + } else if ((str[i] >= 'a') && (str[i] <= 'f')) { + tmp = str[i] - 'a' + 10; + } else if ((str[i] >= 'A') && (str[i] <= 'F')) { + tmp = str[i] - 'A' + 10; + } else { + /* item is in arena and gets freed by the caller */ + return NULL; + } + + byteval = byteval * 16 + tmp; + if ((i % 2) != 0) { + item->data[i / 2] = byteval; + byteval = 0; + } + i++; + } + + return item; +} diff --git a/cmd/lib/basicutil.h b/cmd/lib/basicutil.h index 3eeeef73b4..4b3d5ff36d 100644 --- a/cmd/lib/basicutil.h +++ b/cmd/lib/basicutil.h @@ -80,6 +80,12 @@ SECU_SECItemToHex(const SECItem *item, char *dst); SECStatus SECU_SECItemHexStringToBinary(SECItem *srcdest); +/* +** Read a hex string into a SecItem. +*/ +extern SECItem *SECU_HexString2SECItem(PLArenaPool *arena, SECItem *item, + const char *str); + /* * * Utilities for parsing security tools command lines diff --git a/cmd/lib/secutil.c b/cmd/lib/secutil.c index 9f48f34d49..c5ed068a72 100644 --- a/cmd/lib/secutil.c +++ b/cmd/lib/secutil.c @@ -3833,49 +3833,6 @@ SECU_ParseSSLVersionRangeString(const char *input, return SECSuccess; } -SECItem * -SECU_HexString2SECItem(PLArenaPool *arena, SECItem *item, const char *str) -{ - int i = 0; - int byteval = 0; - int tmp = PORT_Strlen(str); - - PORT_Assert(arena); - PORT_Assert(item); - - if ((tmp % 2) != 0) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - return NULL; - } - - item = SECITEM_AllocItem(arena, item, tmp / 2); - if (item == NULL) { - return NULL; - } - - while (str[i]) { - if ((str[i] >= '0') && (str[i] <= '9')) { - tmp = str[i] - '0'; - } else if ((str[i] >= 'a') && (str[i] <= 'f')) { - tmp = str[i] - 'a' + 10; - } else if ((str[i] >= 'A') && (str[i] <= 'F')) { - tmp = str[i] - 'A' + 10; - } else { - /* item is in arena and gets freed by the caller */ - return NULL; - } - - byteval = byteval * 16 + tmp; - if ((i % 2) != 0) { - item->data[i / 2] = byteval; - byteval = 0; - } - i++; - } - - return item; -} - SSLNamedGroup groupNameToNamedGroup(char *name) {