]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
extensions: enhanced extension lib with pack and unpack functions
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Tue, 3 Oct 2017 06:58:59 +0000 (08:58 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Mon, 19 Feb 2018 14:29:35 +0000 (15:29 +0100)
That allows the functionality to be used for the majority of extensions.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
lib/hello_ext_lib.c
lib/hello_ext_lib.h

index a9ae28caed0a8a1b5de93da39e9b6b0212f7a5b7..547f63a391fbd59c6a413bbdd0c9d1be79ffa0dc 100644 (file)
@@ -78,3 +78,51 @@ _gnutls_hello_ext_get_datum(gnutls_session_t session,
        return 0;
 }
 
+int
+_gnutls_hello_ext_get_resumed_datum(gnutls_session_t session,
+                                   extensions_t id, gnutls_datum_t *data /* constant contents */)
+{
+       gnutls_ext_priv_data_t epriv;
+       int ret;
+
+       ret = _gnutls_hello_ext_get_resumed_sdata(session, id, &epriv);
+       if (ret < 0 || epriv == NULL)
+               return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
+
+       data->size = _gnutls_read_uint16(epriv);
+       data->data = ((uint8_t*)epriv)+2;
+
+       return 0;
+}
+
+int
+_gnutls_hello_ext_default_pack(gnutls_ext_priv_data_t epriv, gnutls_buffer_st *ps)
+{
+       size_t size;
+
+       size = _gnutls_read_uint16(epriv);
+
+       return _gnutls_buffer_append_data(ps, epriv, size+2);
+}
+
+int
+_gnutls_hello_ext_default_unpack(gnutls_buffer_st *ps, gnutls_ext_priv_data_t *epriv)
+{
+       gnutls_datum_t data;
+       uint8_t *store;
+       int ret;
+
+       ret = _gnutls_buffer_pop_datum_prefix16(ps, &data);
+       if (ret < 0)
+               return gnutls_assert_val(ret);
+
+       store = gnutls_calloc(1, data.size+2);
+       if (store == NULL)
+               return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
+       _gnutls_write_uint16(data.size, store);
+       memcpy(store+2, data.data, data.size);
+
+       *epriv = store;
+       return 0;
+}
index 6f1a5c21aa7ca250a33d32903db8b605c9b4e9ac..9ae2be8572970648c5b72896c958066981a295f3 100644 (file)
@@ -26,8 +26,9 @@
 #include <gnutls/gnutls.h>
 #include "hello_ext.h"
 
-void _gnutls_hello_ext_default_deinit(gnutls_ext_priv_data_t priv);
-
+/* Functions to use at the send() or recv() extension function to temporarily
+ * store and retrieve data related to the extension.
+ */
 int
 _gnutls_hello_ext_set_datum(gnutls_session_t session,
                            extensions_t id, const gnutls_datum_t *data);
@@ -35,4 +36,32 @@ int
 _gnutls_hello_ext_get_datum(gnutls_session_t session,
                            extensions_t id, gnutls_datum_t *data /* constant contents */);
 
+int
+_gnutls_hello_ext_get_resumed_datum(gnutls_session_t session,
+                                   extensions_t id, gnutls_datum_t *data /* constant contents */);
+
+/* clear up any set data for the extension */
+#if 0 /* defined in hello_ext.h */
+void
+_gnutls_hello_ext_unset_sdata(gnutls_session_t session,
+                              extensions_t id);
+#endif
+
+/* Function that will deinitialize the temporal data. Must be set
+ * as the deinit_func in the hello_ext_entry_st if the functions above
+ * are used.
+ */
+void _gnutls_hello_ext_default_deinit(gnutls_ext_priv_data_t priv);
+
+/* Functions to pack and unpack data if they need to be stored at
+ * session resumption data. Must be set as the pack_func and unpack_func
+ * of hello_ext_entry_st if the set and get functions above are used,
+ * and data must be accessible on resumed sessions.
+ */
+int
+_gnutls_hello_ext_default_pack(gnutls_ext_priv_data_t epriv, gnutls_buffer_st *ps);
+
+int
+_gnutls_hello_ext_default_unpack(gnutls_buffer_st *ps, gnutls_ext_priv_data_t *epriv);
+
 #endif