Skip to content

Commit

Permalink
8290532: Adjust PKCS11Exception and handle more PKCS11 error codes
Browse files Browse the repository at this point in the history
Backport-of: 07f0612c9aa5641491516d9a0232392689d4c1ca
  • Loading branch information
MBaesken committed Sep 28, 2022
1 parent 4ea5526 commit fa8feb4
Showing 1 changed file with 25 additions and 2 deletions.
Expand Up @@ -209,14 +209,37 @@ static enum RV {
}
};

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;
}

/**
Expand Down

0 comments on commit fa8feb4

Please sign in to comment.