DSA *d2i_DSAPrivateKey(DSA **out, const uint8_t **inp, long len) { if (len < 0) { return NULL; } CBS cbs; CBS_init(&cbs, *inp, (size_t)len); DSA *ret = DSA_parse_private_key(&cbs); if (ret == NULL) { return NULL; } if (out != NULL) { DSA_free(*out); *out = ret; } *inp = CBS_data(&cbs); return ret; }
static EVP_PKEY *old_priv_decode(CBS *cbs, int type) { EVP_PKEY *ret = EVP_PKEY_new(); if (ret == NULL) { return NULL; } switch (type) { case EVP_PKEY_EC: { EC_KEY *ec_key = EC_KEY_parse_private_key(cbs, NULL); if (ec_key == NULL || !EVP_PKEY_assign_EC_KEY(ret, ec_key)) { EC_KEY_free(ec_key); goto err; } return ret; } case EVP_PKEY_DSA: { DSA *dsa = DSA_parse_private_key(cbs); if (dsa == NULL || !EVP_PKEY_assign_DSA(ret, dsa)) { DSA_free(dsa); goto err; } return ret; } case EVP_PKEY_RSA: { RSA *rsa = RSA_parse_private_key(cbs); if (rsa == NULL || !EVP_PKEY_assign_RSA(ret, rsa)) { RSA_free(rsa); goto err; } return ret; } default: OPENSSL_PUT_ERROR(EVP, EVP_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; } err: EVP_PKEY_free(ret); return NULL; }