Skip to content

Commit

Permalink
Bug 1300109 - Move SECU_HexString2SECItem to basicutil.c, r=franziskus
Browse files Browse the repository at this point in the history
Also add the stub declaration in basicutil.h, and remove unnecesary
#include for secutil.h in some files.

--HG--
extra : histedit_source : 68a77d7e83c310fbe880daac11323dfaa71a5f4a
  • Loading branch information
ueno committed Jan 6, 2017
1 parent 94a369f commit 72687e5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
3 changes: 2 additions & 1 deletion cmd/ecperf/ecperf.c
Expand Up @@ -9,7 +9,6 @@
#include "basicutil.h"
#include "pkcs11.h"
#include "nspr.h"
#include "secutil.h"
#include <stdio.h>

#define __PASTE(x, y) x##y
Expand Down Expand Up @@ -106,6 +105,8 @@ typedef struct ThreadDataStr {
int isSign;
} ThreadData;

typedef SECItem SECKEYECParams;

void
PKCS11Thread(void *data)
{
Expand Down
1 change: 0 additions & 1 deletion cmd/fbectest/fbectest.c
Expand Up @@ -9,7 +9,6 @@
#include "basicutil.h"
#include "secder.h"
#include "secitem.h"
#include "secutil.h"
#include "nspr.h"
#include <stdio.h>

Expand Down
43 changes: 43 additions & 0 deletions cmd/lib/basicutil.c
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions cmd/lib/basicutil.h
Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions cmd/lib/secutil.c
Expand Up @@ -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)
{
Expand Down

0 comments on commit 72687e5

Please sign in to comment.