Skip to content

Commit

Permalink
chore(spec): generate_keys supports EC key
Browse files Browse the repository at this point in the history
  • Loading branch information
catbro666 committed Jan 17, 2025
1 parent 6a81453 commit 0cf2e33
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions spec/internal/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,23 @@ end
-- @function generate_keys
-- @param fmt format to receive the public and private pair
-- @return `pub, priv` key tuple or `nil + err` on failure
local function generate_keys(fmt)
local function generate_keys(fmt, typ)
fmt = string.upper(fmt) or "JWK"
local key, err = pkey.new({
-- only support RSA for now
type = 'RSA',
bits = 2048,
exp = 65537
})
typ = string.upper(typ) or "RSA"
local key, err
-- only support RSA and EC for now
if typ == "RSA" then
key, err = pkey.new({
type = 'RSA',
bits = 2048,
exp = 65537
})
else if typ == "EC" then
key, err = pkey.new({
type = 'EC',
curve = 'prime256v1',
})
end
assert(key)
assert(err == nil, err)
local pub = key:tostring("public", fmt)
Expand Down

0 comments on commit 0cf2e33

Please sign in to comment.