Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
From 23c0949786a1a7ac222be2b5391ab2d654342e99 Mon Sep 17 00:00:00 2001
Bug 1162897, pk11wrap: add pk11_MatchString, r=rrelyea
  • Loading branch information
ueno committed May 4, 2017
1 parent 0e99f0e commit bf3a716
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pk11wrap/pk11priv.h
Expand Up @@ -45,6 +45,8 @@ CK_ULONG PK11_ReadULongAttribute(PK11SlotInfo *slot, CK_OBJECT_HANDLE id,
CK_ATTRIBUTE_TYPE type);
char *PK11_MakeString(PLArenaPool *arena, char *space, char *staticSring,
int stringLen);
PRBool pk11_MatchString(const char *string,
const char *staticString, int staticStringLen);
int PK11_MapError(CK_RV error);
CK_SESSION_HANDLE PK11_GetRWSession(PK11SlotInfo *slot);
void PK11_RestoreROSession(PK11SlotInfo *slot, CK_SESSION_HANDLE rwsession);
Expand Down
23 changes: 23 additions & 0 deletions lib/pk11wrap/pk11slot.c
Expand Up @@ -1076,6 +1076,29 @@ PK11_MakeString(PLArenaPool *arena, char *space,
return newString;
}

/*
* check if a null-terminated string matches with a PKCS11 Static Label
*/
PRBool
pk11_MatchString(const char *string,
const char *staticString, int staticStringLen)
{
int i;

for (i = (staticStringLen - 1); i >= 0; i--) {
if (staticString[i] != ' ')
break;
}
/* move i to point to the last space */
i++;

if (strlen(string) == i && memcmp(string, staticString, i) == 0) {
return PR_TRUE;
}

return PR_FALSE;
}

/*
* Reads in the slots mechanism list for later use
*/
Expand Down

0 comments on commit bf3a716

Please sign in to comment.