@@ -485,6 +485,7 @@ int x509_extract_key_data(void *context, size_t hdrlen,
const void *value, size_t vlen)
{
struct x509_parse_context *ctx = context;
+ enum OID oid;
ctx->key_algo = ctx->last_oid;
switch (ctx->last_oid) {
@@ -496,18 +497,20 @@ int x509_extract_key_data(void *context, size_t hdrlen,
ctx->cert->pub->pkey_algo = "ecrdsa";
break;
case OID_id_ecPublicKey:
- ctx->cert->pub->pkey_algo = "sm2";
- if (ctx->params_size > 2) {
- enum OID oid = look_up_OID(ctx->params + 2,
- ctx->params_size - 2);
- switch (oid) {
- case OID_id_prime192v1:
- case OID_id_prime256v1:
- ctx->cert->pub->pkey_algo = "ecdsa";
- break;
- default:
- break;
- }
+ if (ctx->params_size < 2)
+ return -ENOPKG;
+
+ oid = look_up_OID(ctx->params + 2, ctx->params_size - 2);
+ switch (oid) {
+ case OID_id_prime192v1:
+ case OID_id_prime256v1:
+ ctx->cert->pub->pkey_algo = "ecdsa";
+ break;
+ case OID_sm2:
+ ctx->cert->pub->pkey_algo = "sm2";
+ break;
+ default:
+ return -ENOPKG;
}
break;
default: