Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more flexible key:is_private() #308

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ int openssl_pkey_is_private(EVP_PKEY* pkey)
int ret = 0;
int typ;
assert(pkey != NULL);

typ = EVP_PKEY_type(EVP_PKEY_id(pkey));
switch (typ)
{
Expand Down Expand Up @@ -67,6 +68,14 @@ int openssl_pkey_is_private(EVP_PKEY* pkey)
}
#endif
default:
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
{
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pkey, NULL);
if (EVP_PKEY_private_check(ctx))
ret = 1;
EVP_PKEY_CTX_free(ctx);
}
#endif
break;
}

Expand Down
10 changes: 10 additions & 0 deletions test/4.pkey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ function TestPKEYMY:testBasic()
end
end

if helper.openssl3 then
function testED25519()
local key = openssl.pkey.ctx_new('ED25519'):keygen()
assert(key:is_private())
local pem = key:export('pem')
key = openssl.pkey.read(pem, true, 'pem')
assert(key:is_private())
end
end

function testRSA()
local nrsa = {'rsa', 1024, 3}
local rsa = pkey.new(unpack(nrsa))
Expand Down
Loading