Update pin.c

This commit is contained in:
Token2
2024-11-20 09:59:29 +01:00
committed by GitHub
parent 6aef9ceccd
commit b8a9ea4604

View File

@@ -77,6 +77,46 @@ out:
exit(status);
}
int pin_set2(char* path, const char* pin1)
{
fido_dev_t* dev = NULL;
int r;
int status = 1; // Default to failure
// Validate the provided PIN length
if (strlen(pin1) < 4 || strlen(pin1) > 63) {
fprintf(stderr, "invalid PIN length\n");
return status;
}
// Open the device
dev = open_dev(path);
if (!dev) {
fprintf(stderr, "Failed to open device\n");
return status;
}
// Set the PIN
if ((r = fido_dev_set_pin(dev, pin1, NULL)) != FIDO_OK) {
warnx("fido_dev_set_pin: %s", fido_strerr(r));
}
else {
status = 0; // Success
}
// Cleanup
if (dev) {
fido_dev_close(dev);
fido_dev_free(&dev);
}
// Explicitly clear the PIN from memory
explicit_bzero((void*)pin1, strlen(pin1));
return status;
}
int
pin_change(char *path)
{