8290532: Adjust PKCS11Exception and handle more PKCS11 error codes

Reviewed-by: valeriep
This commit is contained in:
Matthias Baesken 2022-07-28 07:30:51 +00:00
parent 93f96d8c9e
commit 07f0612c9a

View File

@ -180,14 +180,37 @@ public class PKCS11Exception extends Exception {
}
};
public static enum RV_VENDOR {
// NSS
CKR_NSS_CERTDB_FAILED(0xCE534351L),
CKR_NSS_KEYDB_FAILED(0xCE534352L);
private final long value;
RV_VENDOR(long value) {
this.value = value;
}
};
private static String lookup(long errorCode) {
for (RV r : RV.values()) {
if (r.value == errorCode) {
return r.name();
}
}
// for unknown PKCS11 return values, just use hex as its string
return "0x" + Functions.toFullHexString((int)errorCode);
// for unknown PKCS11 return values, use hex as its string
String res = "0x" + Functions.toFullHexString((int)errorCode);
// for vendor-defined values, check the enum for vendors and include
// potential matches
if ((errorCode & 0x80000000L) != 0) {
for (RV_VENDOR r : RV_VENDOR.values()) {
if (r.value == errorCode) {
res += "(" + r.name() + ")";
break;
}
}
}
return res;
}
/**