From b321ba8fabf84134f042c53b2a0e8dee4358f71b Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Thu, 16 Feb 2023 10:52:05 -0300 Subject: [PATCH] Fix PSK samples --- samples/psk/client.lua | 15 +++++++++++---- samples/psk/server.lua | 19 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/samples/psk/client.lua b/samples/psk/client.lua index b496a5e..75eeb63 100644 --- a/samples/psk/client.lua +++ b/samples/psk/client.lua @@ -4,13 +4,20 @@ local socket = require("socket") local ssl = require("ssl") +-- @param hint (nil | string) +-- @param max_identity_len (number) +-- @param max_psk_len (number) +-- @return identity (string) +-- @return PSK (string) +local function pskcb(hint, max_identity_len, max_psk_len) + print(string.format("PSK Callback: hint=%q, max_identity_len=%d, max_psk_len=%d", hint, max_identity_len, max_psk_len)) + return "abcd", "1234" +end + local params = { mode = "client", protocol = "tlsv1_2", - psk = function(hint, max_psk_len) - print("PSK Callback: hint=", hint, ", max_psk_len=", max_psk_len) - return "abcd", "1234" - end + psk = pskcb, } local peer = socket.tcp() diff --git a/samples/psk/server.lua b/samples/psk/server.lua index aa9aff8..245c5cd 100644 --- a/samples/psk/server.lua +++ b/samples/psk/server.lua @@ -4,17 +4,22 @@ local socket = require("socket") local ssl = require("ssl") +-- @param identity (string) +-- @param max_psk_len (number) +-- @return psk (string) +local function pskcb(identity, max_psk_len) + print(string.format("PSK Callback: identity=%q, max_psk_len=%d", identity, max_psk_len)) + if identity == "abcd" then + return "1234" + end + return nil +end + local params = { mode = "server", protocol = "any", options = "all", - psk = function(identity, max_psk_len) - print("PSK Callback: identity=", identity, ", max_psk_len=", max_psk_len) - if identity == "abcd" then - return "1234" - end - return nil - end + psk = pskcb, }