Add some PACKET functions for size_t
[openssl.git] / ssl / packet_locl.h
index 517c12d4620789444a973e7ce331573a5abc324c..ec31a331d21a5ec1326e1e7c2714e0e83ae77b73 100644 (file)
@@ -160,6 +160,19 @@ __owur static ossl_inline int PACKET_get_net_2(PACKET *pkt, unsigned int *data)
     return 1;
 }
 
+/* Same as PACKET_get_net_2() but for a size_t */
+__owur static ossl_inline int PACKET_get_net_2_len(PACKET *pkt, size_t *data)
+{
+    unsigned int i;
+    int ret;
+
+    ret = PACKET_get_net_2(pkt, &i);
+    if (ret)
+        *data = (size_t)i;
+
+    return ret;
+}
+
 /*
  * Peek ahead at 3 bytes in network order from |pkt| and store the value in
  * |*data|
@@ -189,6 +202,19 @@ __owur static ossl_inline int PACKET_get_net_3(PACKET *pkt, unsigned long *data)
     return 1;
 }
 
+/* Same as PACKET_get_net_3() but for a size_t */
+__owur static ossl_inline int PACKET_get_net_3_len(PACKET *pkt, size_t *data)
+{
+    unsigned long i;
+    int ret;
+
+    ret = PACKET_get_net_3(pkt, &i);
+    if (ret)
+        *data = (size_t)i;
+
+    return ret;
+}
+
 /*
  * Peek ahead at 4 bytes in network order from |pkt| and store the value in
  * |*data|
@@ -219,6 +245,19 @@ __owur static ossl_inline int PACKET_get_net_4(PACKET *pkt, unsigned long *data)
     return 1;
 }
 
+/* Same as PACKET_get_net_4() but for a size_t */
+__owur static ossl_inline int PACKET_get_net_4_len(PACKET *pkt, size_t *data)
+{
+    unsigned long i;
+    int ret;
+
+    ret = PACKET_get_net_4(pkt, &i);
+    if (ret)
+        *data = (size_t)i;
+
+    return ret;
+}
+
 /* Peek ahead at 1 byte from |pkt| and store the value in |*data| */
 __owur static ossl_inline int PACKET_peek_1(const PACKET *pkt,
                                             unsigned int *data)
@@ -242,6 +281,19 @@ __owur static ossl_inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
     return 1;
 }
 
+/* Same as PACKET_get_1() but for a size_t */
+__owur static ossl_inline int PACKET_get_1_len(PACKET *pkt, size_t *data)
+{
+    unsigned int i;
+    int ret;
+
+    ret = PACKET_get_1(pkt, &i);
+    if (ret)
+        *data = (size_t)i;
+
+    return ret;
+}
+
 /*
  * Peek ahead at 4 bytes in reverse network order from |pkt| and store the value
  * in |*data|
@@ -707,7 +759,7 @@ int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len,
  * maximum size will be. If this function is used, then it should be immediately
  * followed by a WPACKET_allocate_bytes() call before any other WPACKET
  * functions are called (unless the write to the allocated bytes is abandoned).
- * 
+ *
  * For example: If we are generating a signature, then the size of that
  * signature may not be known in advance. We can use WPACKET_reserve_bytes() to
  * handle this:
@@ -758,7 +810,7 @@ int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t bytes);
 #define WPACKET_put_bytes_u24(pkt, val) \
     WPACKET_put_bytes__((pkt), (val), 3)
 #define WPACKET_put_bytes_u32(pkt, val) \
-    WPACKET_sub_allocate_bytes__((pkt), (val), 4)
+    WPACKET_put_bytes__((pkt), (val), 4)
 
 /* Set a maximum size that we will not allow the WPACKET to grow beyond */
 int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize);