From 0cf2e33f417d2ffc1ea6ee28e2846d382518c530 Mon Sep 17 00:00:00 2001 From: Zhefeng Chen Date: Fri, 17 Jan 2025 16:03:24 +0800 Subject: [PATCH] chore(spec): generate_keys supports EC key --- spec/internal/misc.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spec/internal/misc.lua b/spec/internal/misc.lua index c02d3683c2c3..407ba537834c 100644 --- a/spec/internal/misc.lua +++ b/spec/internal/misc.lua @@ -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)