diff options
author | Daiki Ueno <dueno@redhat.com> | 2017-05-04 20:35:53 +0200 |
---|---|---|
committer | Daiki Ueno <dueno@redhat.com> | 2017-05-04 20:35:53 +0200 |
commit | efdfa58090b59772eb1b6aa0beea26bf184346f4 (patch) | |
tree | d0b403ceff907efc87766c4b0f91a601d681b359 | |
parent | 2cec199bc425aafc050fd18bbdc6b759d3ad2a61 (diff) | |
download | nss-hg-efdfa58090b59772eb1b6aa0beea26bf184346f4.tar.gz |
From 23c0949786a1a7ac222be2b5391ab2d654342e99 Mon Sep 17 00:00:00 2001
Bug 1162897, pk11wrap: add pk11_MatchString, r=rrelyea
-rw-r--r-- | lib/pk11wrap/pk11priv.h | 2 | ||||
-rw-r--r-- | lib/pk11wrap/pk11slot.c | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/pk11wrap/pk11priv.h b/lib/pk11wrap/pk11priv.h index d9aaeaf92..7567ecc34 100644 --- a/lib/pk11wrap/pk11priv.h +++ b/lib/pk11wrap/pk11priv.h @@ -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); diff --git a/lib/pk11wrap/pk11slot.c b/lib/pk11wrap/pk11slot.c index 68d37486f..f58394b77 100644 --- a/lib/pk11wrap/pk11slot.c +++ b/lib/pk11wrap/pk11slot.c @@ -1077,6 +1077,29 @@ PK11_MakeString(PLArenaPool *arena, char *space, } /* + * 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 */ SECStatus |