if (bytes_read < 0)
break;
- // Increment the line counter
- lineno++;
+ // Decode the key
+ r = pakfire_b64decode(pakfire, &buffer, &buffer_length, line);
+ if (r) {
+ ERROR(pakfire, "Could not decode the key: %m\n");
+ errno = EINVAL;
+ r = 1;
+ goto ERROR;
+ }
- switch (lineno) {
- // The first line must start with "untrusted comment:"
- case 1:
- if (!pakfire_string_startswith(line, "untrusted comment:")) {
- ERROR(pakfire, "The first line must start with 'untrusted comment:'\n");
- errno = EINVAL;
- r = 1;
- goto ERROR;
- }
+ // What kind of key do we have?
+ switch (buffer_length) {
+ // Public Key
+ case sizeof(struct pakfire_key_public_key):
+ r = pakfire_key_import_public_key(key, pakfire,
+ (struct pakfire_key_public_key*)buffer);
break;
- // The second line should hold the key
- case 2:
- // Decode the key
- r = pakfire_b64decode(pakfire, &buffer, &buffer_length, line);
- if (r) {
- ERROR(pakfire, "Could not decode the key: %m\n");
- errno = EINVAL;
- r = 1;
- goto ERROR;
- }
-
- // What kind of key do we have?
- switch (buffer_length) {
- // Public Key
- case sizeof(struct pakfire_key_public_key):
- r = pakfire_key_import_public_key(key, pakfire,
- (struct pakfire_key_public_key*)buffer);
- break;
-
- // Private Key
- case sizeof(struct pakfire_key_private_key):
- r = pakfire_key_import_secret_key(key, pakfire,
- (struct pakfire_key_private_key*)buffer);
- break;
-
- // Unknown key
- default:
- ERROR(pakfire, "Unsupported key type\n");
- errno = ENOTSUP;
- r = 1;
- goto ERROR;
- }
+ // Private Key
+ case sizeof(struct pakfire_key_private_key):
+ r = pakfire_key_import_secret_key(key, pakfire,
+ (struct pakfire_key_private_key*)buffer);
break;
- // Ignore any further data
+ // Unknown key
default:
- break;
+ ERROR(pakfire, "Unsupported key type\n");
+ errno = ENOTSUP;
+ r = 1;
+ goto ERROR;
}
}