From 8ae6b8eca561d0ed44659062acc91c7bae983dde Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 24 Jun 2023 22:54:27 +0200 Subject: [PATCH] add a function to initialize session ticket keys in a Config --- unsafe.go | 5 +++++ unsafe_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/unsafe.go b/unsafe.go index 55fa01b..67a7567 100644 --- a/unsafe.go +++ b/unsafe.go @@ -94,3 +94,8 @@ func compareStruct(a, b reflect.Type) bool { } return true } + +// InitSessionTicketKeys triggers the initialization of session ticket keys. +func InitSessionTicketKeys(conf *Config) { + fromConfig(conf).ticketKeys(nil) +} diff --git a/unsafe_test.go b/unsafe_test.go index 0e4ae77..36663a0 100644 --- a/unsafe_test.go +++ b/unsafe_test.go @@ -170,3 +170,17 @@ func TestClientSessionStateReinterpretCast(t *testing.T) { // t.Fatal("failed") // } // } + +func TestInitSessionTicketKeys(t *testing.T) { + c1 := testConfig.Clone() + InitSessionTicketKeys(c1) + c2 := c1.Clone() + + stk := fromConfig(c1).autoSessionTicketKeys + if len(stk) == 0 { + t.Fatal("no session ticket keys") + } + if !reflect.DeepEqual(stk, fromConfig(c2).autoSessionTicketKeys) { + t.Fatal("session ticket keys don't match") + } +}