Skip to content

Commit d5a7844

Browse files
authored
fix: p11rm was missing the ability to delete all objects of one class (#70)
p11rm was missing the ability to delete all objects of a class. This change allows users to use specific keywords as shortcuts for object classes when removing PKCS#11 objects by label. It's a fix, as the command is documented to support this feature.
1 parent e537a74 commit d5a7844

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/pkcs11_rm.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,26 @@ int pkcs11_rm_objects_with_label(pkcs11Context *p11Context, char *label, int int
3434

3535
int rv=0;
3636
pkcs11Search *search=NULL;
37-
38-
3937
pkcs11IdTemplate *idtmpl=NULL;
4038

41-
idtmpl = pkcs11_create_id(label);
39+
/* trick: we treat "cert", "pubk", "prvk", "seck" and "data" in front of the templating system */
40+
/* so these specific labels can be used as shortcut for the corresponding object classes */
41+
42+
if(label!=NULL) {
43+
if(strcasecmp("cert",label)==0) {
44+
idtmpl = pkcs11_make_idtemplate(CLASS_CERT);
45+
} else if (strcasecmp("pubk",label)==0) {
46+
idtmpl = pkcs11_make_idtemplate(CLASS_PUBK);
47+
} else if (strcasecmp("prvk",label)==0) {
48+
idtmpl = pkcs11_make_idtemplate(CLASS_PRVK);
49+
} else if (strcasecmp("seck",label)==0) {
50+
idtmpl = pkcs11_make_idtemplate(CLASS_SECK);
51+
} else if (strcasecmp("data",label)==0) {
52+
idtmpl = pkcs11_make_idtemplate(CLASS_DATA);
53+
} else {
54+
idtmpl = pkcs11_create_id(label);
55+
}
56+
}
4257

4358
if(idtmpl && pkcs11_sizeof_idtemplate(idtmpl)>0) {
4459

0 commit comments

Comments
 (0)