A simple library to support serving https.

Dependents:   oldheating gps motorhome heating

Revision:
2:82268409e83f
Child:
5:ee5489ee1117
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tls/tls-session.c	Wed Jul 31 15:12:34 2019 +0000
@@ -0,0 +1,37 @@
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "tls-session.h"
+#include "mstimer.h"
+
+#define TLS_MAX_SESSIONS 4
+
+static struct TlsSession sessions[TLS_MAX_SESSIONS];
+
+struct TlsSession* TlsSessionGetOldest()
+{
+    struct TlsSession* pOldest = 0;
+    uint32_t ageOldest = 0;
+    for (int i = 0; i < TLS_MAX_SESSIONS; i++)
+    {
+        if (!sessions[i].state) return sessions + i;   //Found an empty slot so just return it
+        uint32_t age = MsTimerCount - sessions[i].lastUsed;
+        if (age >= ageOldest)
+        {
+            ageOldest = age;
+              pOldest = sessions + i;
+        }
+    }  
+    return pOldest;                            //Otherwise return the oldest
+}
+
+struct TlsSession* TlsSessionGetFromIndex(int sessionIndex)
+{
+    if (sessionIndex <                 0) return 0;
+    if (sessionIndex >= TLS_MAX_SESSIONS) return 0;
+    return &sessions[sessionIndex];
+}
+int TlsSessionGetIndex(struct TlsSession* pSession)
+{
+    return pSession - sessions;
+}
\ No newline at end of file