quic_record_test_util.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_RECORD_TEST_UTIL_H
  10. # define OSSL_RECORD_TEST_UTIL_H
  11. static int cmp_pkt_hdr(const QUIC_PKT_HDR *a, const QUIC_PKT_HDR *b,
  12. const unsigned char *b_data, size_t b_len,
  13. int cmp_data)
  14. {
  15. int ok = 1;
  16. if (b_data == NULL) {
  17. b_data = b->data;
  18. b_len = b->len;
  19. }
  20. if (!TEST_int_eq(a->type, b->type)
  21. || !TEST_int_eq(a->spin_bit, b->spin_bit)
  22. || !TEST_int_eq(a->key_phase, b->key_phase)
  23. || !TEST_int_eq(a->pn_len, b->pn_len)
  24. || !TEST_int_eq(a->partial, b->partial)
  25. || !TEST_int_eq(a->fixed, b->fixed)
  26. || !TEST_int_eq(a->unused, b->unused)
  27. || !TEST_int_eq(a->reserved, b->reserved)
  28. || !TEST_uint_eq(a->version, b->version)
  29. || !TEST_true(ossl_quic_conn_id_eq(&a->dst_conn_id, &b->dst_conn_id))
  30. || !TEST_true(ossl_quic_conn_id_eq(&a->src_conn_id, &b->src_conn_id))
  31. || !TEST_mem_eq(a->pn, sizeof(a->pn), b->pn, sizeof(b->pn))
  32. || !TEST_size_t_eq(a->token_len, b->token_len)
  33. || !TEST_uint64_t_eq(a->len, b->len))
  34. ok = 0;
  35. if (a->token_len > 0 && b->token_len > 0
  36. && !TEST_mem_eq(a->token, a->token_len, b->token, b->token_len))
  37. ok = 0;
  38. if ((a->token_len == 0 && !TEST_ptr_null(a->token))
  39. || (b->token_len == 0 && !TEST_ptr_null(b->token)))
  40. ok = 0;
  41. if (cmp_data && !TEST_mem_eq(a->data, a->len, b_data, b_len))
  42. ok = 0;
  43. return ok;
  44. }
  45. #endif