@fails-components/webtransport 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/package.json +1 -1
  2. package/readme.md +1 -3
  3. package/src/http3eventloop.cc +83 -9
  4. package/src/http3eventloop.h +13 -3
  5. package/src/http3server.cc +22 -22
  6. package/src/http3server.h +7 -20
  7. package/src/http3wtstreamvisitor.cc +31 -10
  8. package/src/http3wtstreamvisitor.h +38 -11
  9. package/src/webtransport.js +91 -23
  10. package/test/echoserver.js +29 -5
  11. package/test/testsuite.js +242 -220
  12. package/third_party/boringssl/src/CMakeLists.txt +2 -0
  13. package/third_party/boringssl/src/crypto/CMakeLists.txt +1 -0
  14. package/third_party/boringssl/src/crypto/asn1/a_bitstr.c +174 -177
  15. package/third_party/boringssl/src/crypto/asn1/a_bool.c +46 -48
  16. package/third_party/boringssl/src/crypto/asn1/a_d2i_fp.c +21 -23
  17. package/third_party/boringssl/src/crypto/asn1/a_dup.c +21 -23
  18. package/third_party/boringssl/src/crypto/asn1/a_gentm.c +84 -187
  19. package/third_party/boringssl/src/crypto/asn1/a_i2d_fp.c +19 -21
  20. package/third_party/boringssl/src/crypto/asn1/a_int.c +305 -329
  21. package/third_party/boringssl/src/crypto/asn1/a_mbstr.c +190 -195
  22. package/third_party/boringssl/src/crypto/asn1/a_object.c +182 -189
  23. package/third_party/boringssl/src/crypto/asn1/a_octet.c +6 -9
  24. package/third_party/boringssl/src/crypto/asn1/a_print.c +15 -16
  25. package/third_party/boringssl/src/crypto/asn1/a_strex.c +386 -399
  26. package/third_party/boringssl/src/crypto/asn1/a_strnid.c +110 -131
  27. package/third_party/boringssl/src/crypto/asn1/a_time.c +118 -111
  28. package/third_party/boringssl/src/crypto/asn1/a_type.c +59 -60
  29. package/third_party/boringssl/src/crypto/asn1/a_utctm.c +114 -186
  30. package/third_party/boringssl/src/crypto/asn1/a_utf8.c +171 -159
  31. package/third_party/boringssl/src/crypto/asn1/asn1_lib.c +245 -260
  32. package/third_party/boringssl/src/crypto/asn1/asn1_par.c +41 -40
  33. package/third_party/boringssl/src/crypto/asn1/asn1_test.cc +31 -0
  34. package/third_party/boringssl/src/crypto/asn1/asn_pack.c +31 -33
  35. package/third_party/boringssl/src/crypto/asn1/f_int.c +36 -33
  36. package/third_party/boringssl/src/crypto/asn1/f_string.c +29 -26
  37. package/third_party/boringssl/src/crypto/asn1/internal.h +62 -61
  38. package/third_party/boringssl/src/crypto/asn1/tasn_dec.c +706 -702
  39. package/third_party/boringssl/src/crypto/asn1/tasn_enc.c +507 -524
  40. package/third_party/boringssl/src/crypto/asn1/tasn_fre.c +141 -133
  41. package/third_party/boringssl/src/crypto/asn1/tasn_new.c +207 -199
  42. package/third_party/boringssl/src/crypto/asn1/tasn_typ.c +19 -22
  43. package/third_party/boringssl/src/crypto/asn1/tasn_utl.c +24 -24
  44. package/third_party/boringssl/src/crypto/asn1/time_support.c +13 -13
  45. package/third_party/boringssl/src/crypto/bio/connect.c +9 -3
  46. package/third_party/boringssl/src/crypto/bytestring/bytestring_test.cc +125 -1
  47. package/third_party/boringssl/src/crypto/bytestring/cbb.c +4 -7
  48. package/third_party/boringssl/src/crypto/bytestring/cbs.c +167 -9
  49. package/third_party/boringssl/src/crypto/cipher_extra/e_aesctrhmac.c +0 -2
  50. package/third_party/boringssl/src/crypto/cipher_extra/e_aesgcmsiv.c +23 -54
  51. package/third_party/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c +0 -2
  52. package/third_party/boringssl/src/crypto/cipher_extra/e_tls.c +0 -2
  53. package/third_party/boringssl/src/crypto/curve25519/curve25519.c +6 -8
  54. package/third_party/boringssl/src/crypto/evp/evp_ctx.c +25 -22
  55. package/third_party/boringssl/src/crypto/evp/internal.h +15 -9
  56. package/third_party/boringssl/src/crypto/evp/p_dsa_asn1.c +2 -0
  57. package/third_party/boringssl/src/crypto/evp/p_ec_asn1.c +2 -0
  58. package/third_party/boringssl/src/crypto/evp/p_ed25519.c +3 -3
  59. package/third_party/boringssl/src/crypto/evp/p_ed25519_asn1.c +10 -7
  60. package/third_party/boringssl/src/crypto/evp/p_hkdf.c +241 -0
  61. package/third_party/boringssl/src/crypto/evp/p_rsa_asn1.c +2 -0
  62. package/third_party/boringssl/src/crypto/evp/p_x25519_asn1.c +1 -0
  63. package/third_party/boringssl/src/crypto/fipsmodule/aes/aes_nohw.c +9 -10
  64. package/third_party/boringssl/src/crypto/fipsmodule/aes/key_wrap.c +2 -6
  65. package/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.c +5 -11
  66. package/third_party/boringssl/src/crypto/fipsmodule/bn/internal.h +1 -1
  67. package/third_party/boringssl/src/crypto/fipsmodule/bn/prime.c +2 -0
  68. package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aes.c +10 -26
  69. package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aesccm.c +2 -3
  70. package/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.c +1 -0
  71. package/third_party/boringssl/src/crypto/fipsmodule/ec/p256-nistz.c +44 -43
  72. package/third_party/boringssl/src/crypto/fipsmodule/modes/cbc.c +5 -9
  73. package/third_party/boringssl/src/crypto/fipsmodule/modes/gcm.c +14 -21
  74. package/third_party/boringssl/src/crypto/fipsmodule/rand/ctrdrbg.c +8 -8
  75. package/third_party/boringssl/src/crypto/fipsmodule/rand/internal.h +1 -4
  76. package/third_party/boringssl/src/crypto/hkdf/hkdf_test.cc +104 -0
  77. package/third_party/boringssl/src/crypto/internal.h +18 -4
  78. package/third_party/boringssl/src/crypto/lhash/internal.h +13 -1
  79. package/third_party/boringssl/src/crypto/obj/obj_dat.h +4 -1
  80. package/third_party/boringssl/src/crypto/obj/obj_mac.num +1 -0
  81. package/third_party/boringssl/src/crypto/obj/objects.txt +2 -0
  82. package/third_party/boringssl/src/crypto/pem/pem_all.c +77 -86
  83. package/third_party/boringssl/src/crypto/pem/pem_info.c +221 -233
  84. package/third_party/boringssl/src/crypto/pem/pem_lib.c +639 -608
  85. package/third_party/boringssl/src/crypto/pem/pem_oth.c +17 -16
  86. package/third_party/boringssl/src/crypto/pem/pem_pk8.c +133 -142
  87. package/third_party/boringssl/src/crypto/pem/pem_pkey.c +96 -92
  88. package/third_party/boringssl/src/crypto/poly1305/poly1305_vec.c +12 -28
  89. package/third_party/boringssl/src/crypto/siphash/siphash.c +8 -11
  90. package/third_party/boringssl/src/crypto/siphash/siphash_test.cc +5 -7
  91. package/third_party/boringssl/src/crypto/stack/stack.c +33 -16
  92. package/third_party/boringssl/src/crypto/thread_pthread.c +0 -2
  93. package/third_party/boringssl/src/crypto/thread_win.c +0 -2
  94. package/third_party/boringssl/src/crypto/trust_token/internal.h +14 -0
  95. package/third_party/boringssl/src/crypto/trust_token/pmbtoken.c +127 -30
  96. package/third_party/boringssl/src/crypto/trust_token/trust_token.c +40 -0
  97. package/third_party/boringssl/src/crypto/trust_token/trust_token_test.cc +165 -0
  98. package/third_party/boringssl/src/crypto/trust_token/voprf.c +55 -6
  99. package/third_party/boringssl/src/crypto/x509/a_digest.c +23 -24
  100. package/third_party/boringssl/src/crypto/x509/a_sign.c +52 -55
  101. package/third_party/boringssl/src/crypto/x509/a_verify.c +33 -34
  102. package/third_party/boringssl/src/crypto/x509/algorithm.c +17 -18
  103. package/third_party/boringssl/src/crypto/x509/asn1_gen.c +618 -612
  104. package/third_party/boringssl/src/crypto/x509/by_dir.c +320 -337
  105. package/third_party/boringssl/src/crypto/x509/by_file.c +186 -186
  106. package/third_party/boringssl/src/crypto/x509/i2d_pr.c +11 -14
  107. package/third_party/boringssl/src/crypto/x509/internal.h +22 -22
  108. package/third_party/boringssl/src/crypto/x509/name_print.c +155 -150
  109. package/third_party/boringssl/src/crypto/x509/rsa_pss.c +27 -29
  110. package/third_party/boringssl/src/crypto/x509/t_crl.c +67 -70
  111. package/third_party/boringssl/src/crypto/x509/t_req.c +3 -5
  112. package/third_party/boringssl/src/crypto/x509/t_x509.c +280 -251
  113. package/third_party/boringssl/src/crypto/x509/t_x509a.c +52 -47
  114. package/third_party/boringssl/src/crypto/x509/x509.c +3 -4
  115. package/third_party/boringssl/src/crypto/x509/x509_att.c +234 -223
  116. package/third_party/boringssl/src/crypto/x509/x509_cmp.c +286 -296
  117. package/third_party/boringssl/src/crypto/x509/x509_d2.c +37 -32
  118. package/third_party/boringssl/src/crypto/x509/x509_def.c +14 -30
  119. package/third_party/boringssl/src/crypto/x509/x509_ext.c +55 -84
  120. package/third_party/boringssl/src/crypto/x509/x509_lu.c +545 -581
  121. package/third_party/boringssl/src/crypto/x509/x509_obj.c +131 -121
  122. package/third_party/boringssl/src/crypto/x509/x509_req.c +120 -139
  123. package/third_party/boringssl/src/crypto/x509/x509_set.c +128 -142
  124. package/third_party/boringssl/src/crypto/x509/x509_trs.c +185 -193
  125. package/third_party/boringssl/src/crypto/x509/x509_txt.c +70 -72
  126. package/third_party/boringssl/src/crypto/x509/x509_v3.c +172 -161
  127. package/third_party/boringssl/src/crypto/x509/x509_vfy.c +2041 -2053
  128. package/third_party/boringssl/src/crypto/x509/x509_vpm.c +441 -461
  129. package/third_party/boringssl/src/crypto/x509/x509cset.c +152 -170
  130. package/third_party/boringssl/src/crypto/x509/x509name.c +274 -260
  131. package/third_party/boringssl/src/crypto/x509/x509rset.c +43 -20
  132. package/third_party/boringssl/src/crypto/x509/x509spki.c +62 -63
  133. package/third_party/boringssl/src/crypto/x509/x_algor.c +64 -62
  134. package/third_party/boringssl/src/crypto/x509/x_all.c +103 -133
  135. package/third_party/boringssl/src/crypto/x509/x_attrib.c +23 -24
  136. package/third_party/boringssl/src/crypto/x509/x_crl.c +310 -321
  137. package/third_party/boringssl/src/crypto/x509/x_exten.c +6 -5
  138. package/third_party/boringssl/src/crypto/x509/x_info.c +31 -28
  139. package/third_party/boringssl/src/crypto/x509/x_name.c +361 -365
  140. package/third_party/boringssl/src/crypto/x509/x_pkey.c +38 -32
  141. package/third_party/boringssl/src/crypto/x509/x_pubkey.c +114 -117
  142. package/third_party/boringssl/src/crypto/x509/x_req.c +27 -29
  143. package/third_party/boringssl/src/crypto/x509/x_sig.c +2 -2
  144. package/third_party/boringssl/src/crypto/x509/x_spki.c +8 -10
  145. package/third_party/boringssl/src/crypto/x509/x_val.c +2 -2
  146. package/third_party/boringssl/src/crypto/x509/x_x509.c +212 -226
  147. package/third_party/boringssl/src/crypto/x509/x_x509a.c +112 -109
  148. package/third_party/boringssl/src/crypto/x509v3/ext_dat.h +10 -13
  149. package/third_party/boringssl/src/crypto/x509v3/internal.h +72 -87
  150. package/third_party/boringssl/src/crypto/x509v3/pcy_cache.c +184 -176
  151. package/third_party/boringssl/src/crypto/x509v3/pcy_data.c +58 -56
  152. package/third_party/boringssl/src/crypto/x509v3/pcy_lib.c +71 -70
  153. package/third_party/boringssl/src/crypto/x509v3/pcy_map.c +56 -58
  154. package/third_party/boringssl/src/crypto/x509v3/pcy_node.c +89 -91
  155. package/third_party/boringssl/src/crypto/x509v3/pcy_tree.c +585 -590
  156. package/third_party/boringssl/src/crypto/x509v3/v3_akey.c +118 -112
  157. package/third_party/boringssl/src/crypto/x509v3/v3_akeya.c +3 -3
  158. package/third_party/boringssl/src/crypto/x509v3/v3_alt.c +447 -451
  159. package/third_party/boringssl/src/crypto/x509v3/v3_bcons.c +44 -38
  160. package/third_party/boringssl/src/crypto/x509v3/v3_bitst.c +39 -43
  161. package/third_party/boringssl/src/crypto/x509v3/v3_conf.c +321 -320
  162. package/third_party/boringssl/src/crypto/x509v3/v3_cpols.c +352 -327
  163. package/third_party/boringssl/src/crypto/x509v3/v3_crld.c +437 -383
  164. package/third_party/boringssl/src/crypto/x509v3/v3_enum.c +23 -16
  165. package/third_party/boringssl/src/crypto/x509v3/v3_extku.c +62 -53
  166. package/third_party/boringssl/src/crypto/x509v3/v3_genn.c +118 -115
  167. package/third_party/boringssl/src/crypto/x509v3/v3_ia5.c +30 -31
  168. package/third_party/boringssl/src/crypto/x509v3/v3_info.c +112 -98
  169. package/third_party/boringssl/src/crypto/x509v3/v3_int.c +40 -15
  170. package/third_party/boringssl/src/crypto/x509v3/v3_lib.c +248 -252
  171. package/third_party/boringssl/src/crypto/x509v3/v3_ncons.c +390 -386
  172. package/third_party/boringssl/src/crypto/x509v3/v3_ocsp.c +45 -32
  173. package/third_party/boringssl/src/crypto/x509v3/v3_pci.c +206 -209
  174. package/third_party/boringssl/src/crypto/x509v3/v3_pcia.c +6 -8
  175. package/third_party/boringssl/src/crypto/x509v3/v3_pcons.c +54 -50
  176. package/third_party/boringssl/src/crypto/x509v3/v3_pmaps.c +66 -65
  177. package/third_party/boringssl/src/crypto/x509v3/v3_prn.c +144 -133
  178. package/third_party/boringssl/src/crypto/x509v3/v3_purp.c +695 -709
  179. package/third_party/boringssl/src/crypto/x509v3/v3_skey.c +75 -69
  180. package/third_party/boringssl/src/crypto/x509v3/v3_utl.c +1102 -1082
  181. package/third_party/boringssl/src/include/openssl/base.h +3 -1
  182. package/third_party/boringssl/src/include/openssl/bn.h +3 -0
  183. package/third_party/boringssl/src/include/openssl/bytestring.h +20 -0
  184. package/third_party/boringssl/src/include/openssl/evp.h +6 -5
  185. package/third_party/boringssl/src/include/openssl/kdf.h +91 -0
  186. package/third_party/boringssl/src/include/openssl/nid.h +4 -0
  187. package/third_party/boringssl/src/include/openssl/ssl.h +6 -1
  188. package/third_party/boringssl/src/include/openssl/stack.h +47 -32
  189. package/third_party/boringssl/src/include/openssl/trust_token.h +18 -3
  190. package/third_party/boringssl/src/include/openssl/x509.h +18 -0
  191. package/third_party/boringssl/src/ssl/ssl_file.cc +61 -99
  192. package/third_party/boringssl/src/ssl/ssl_test.cc +101 -0
  193. package/third_party/boringssl/src/util/doc.config +2 -1
  194. package/third_party/boringssl/src/util/fipstools/acvp/acvptool/subprocess/subprocess.go +8 -0
  195. package/third_party/googleurl/AUTHORS +16 -2
  196. package/third_party/googleurl/base/BUILD +1 -0
  197. package/third_party/googleurl/base/compiler_specific.h +16 -17
  198. package/third_party/googleurl/base/containers/contiguous_iterator.h +13 -9
  199. package/third_party/googleurl/base/containers/span.h +23 -8
  200. package/third_party/googleurl/base/memory/raw_ptr.h +17 -25
  201. package/third_party/googleurl/base/memory/raw_ptr_exclusion.h +21 -0
  202. package/third_party/googleurl/base/strings/escape.cc +14 -2
  203. package/third_party/googleurl/base/strings/safe_sprintf.h +1 -1
  204. package/third_party/googleurl/base/strings/string_number_conversions.cc +5 -3
  205. package/third_party/googleurl/base/strings/string_number_conversions_internal.h +5 -5
  206. package/third_party/googleurl/base/strings/string_piece.h +3 -3
  207. package/third_party/googleurl/base/strings/string_util.cc +4 -27
  208. package/third_party/googleurl/base/strings/string_util.h +43 -8
  209. package/third_party/googleurl/base/strings/string_util_internal.h +11 -12
  210. package/third_party/googleurl/base/strings/string_util_unittest.cc +33 -0
  211. package/third_party/googleurl/base/strings/string_util_win.cc +0 -5
  212. package/third_party/googleurl/base/strings/string_util_win.h +9 -1
  213. package/third_party/googleurl/base/strings/utf_offset_string_conversions.cc +1 -1
  214. package/third_party/googleurl/base/strings/utf_string_conversion_utils.cc +5 -8
  215. package/third_party/googleurl/base/strings/utf_string_conversion_utils.h +13 -10
  216. package/third_party/googleurl/base/strings/utf_string_conversions.cc +32 -25
  217. package/third_party/googleurl/base/template_util.h +23 -35
  218. package/third_party/googleurl/build/build_config.h +14 -3
  219. package/third_party/googleurl/copy.bara.sky +1 -1
  220. package/third_party/googleurl/url/gurl.cc +8 -4
  221. package/third_party/googleurl/url/gurl.h +1 -0
  222. package/third_party/googleurl/url/gurl_unittest.cc +1 -0
  223. package/third_party/googleurl/url/origin.h +36 -26
  224. package/third_party/googleurl/url/scheme_host_port.h +4 -1
  225. package/third_party/googleurl/url/url_canon.h +2 -1
  226. package/third_party/googleurl/url/url_canon_internal.cc +9 -7
  227. package/third_party/googleurl/url/url_canon_internal.h +16 -16
  228. package/third_party/googleurl/url/url_canon_stdstring.h +2 -1
  229. package/third_party/googleurl/url/url_util.cc +9 -8
  230. package/third_party/quiche/build/source_list.bzl +7 -0
  231. package/third_party/quiche/build/source_list.gni +7 -0
  232. package/third_party/quiche/build/source_list.json +7 -0
  233. package/third_party/quiche/quiche/common/platform/api/quiche_mem_slice.h +7 -3
  234. package/third_party/quiche/quiche/http2/adapter/nghttp2_adapter_test.cc +86 -2
  235. package/third_party/quiche/quiche/http2/adapter/oghttp2_adapter_test.cc +104 -2
  236. package/third_party/quiche/quiche/http2/adapter/oghttp2_session.cc +23 -0
  237. package/third_party/quiche/quiche/http2/adapter/oghttp2_session.h +6 -1
  238. package/third_party/quiche/quiche/quic/core/congestion_control/send_algorithm_test.cc +0 -16
  239. package/third_party/quiche/quiche/quic/core/crypto/crypto_protocol.h +1 -1
  240. package/third_party/quiche/quiche/quic/core/http/end_to_end_test.cc +56 -2
  241. package/third_party/quiche/quiche/quic/core/http/http_constants.cc +1 -0
  242. package/third_party/quiche/quiche/quic/core/http/http_constants.h +1 -0
  243. package/third_party/quiche/quiche/quic/core/http/http_encoder.cc +28 -17
  244. package/third_party/quiche/quiche/quic/core/http/http_encoder.h +5 -0
  245. package/third_party/quiche/quiche/quic/core/http/http_encoder_test.cc +26 -30
  246. package/third_party/quiche/quiche/quic/core/http/http_frames.h +1 -0
  247. package/third_party/quiche/quiche/quic/core/http/quic_server_session_base.cc +4 -4
  248. package/third_party/quiche/quiche/quic/core/http/quic_server_session_base_test.cc +1 -1
  249. package/third_party/quiche/quiche/quic/core/http/quic_spdy_client_session.cc +5 -1
  250. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.cc +6 -33
  251. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.h +0 -17
  252. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream_test.cc +5 -20
  253. package/third_party/quiche/quiche/quic/core/io/quic_event_loop.h +81 -0
  254. package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop.cc +265 -0
  255. package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop.h +152 -0
  256. package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop_test.cc +341 -0
  257. package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store.cc +3 -1
  258. package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store.h +7 -7
  259. package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store_test.cc +4 -3
  260. package/third_party/quiche/quiche/quic/core/quic_connection.cc +69 -19
  261. package/third_party/quiche/quiche/quic/core/quic_connection.h +9 -3
  262. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager.cc +29 -10
  263. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager.h +5 -3
  264. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager_test.cc +85 -22
  265. package/third_party/quiche/quiche/quic/core/quic_connection_test.cc +186 -30
  266. package/third_party/quiche/quiche/quic/core/quic_crypto_stream.cc +2 -1
  267. package/third_party/quiche/quiche/quic/core/quic_default_clock.cc +31 -0
  268. package/third_party/quiche/quiche/quic/core/quic_default_clock.h +34 -0
  269. package/third_party/quiche/quiche/quic/core/quic_default_connection_helper.h +49 -0
  270. package/third_party/quiche/quiche/quic/core/quic_dispatcher.cc +53 -37
  271. package/third_party/quiche/quiche/quic/core/quic_dispatcher.h +19 -11
  272. package/third_party/quiche/quiche/quic/core/quic_dispatcher_test.cc +15 -2
  273. package/third_party/quiche/quiche/quic/core/quic_flags_list.h +10 -4
  274. package/third_party/quiche/quiche/quic/core/quic_idle_network_detector.cc +2 -2
  275. package/third_party/quiche/quiche/quic/core/quic_idle_network_detector_test.cc +4 -4
  276. package/third_party/quiche/quiche/quic/core/quic_packet_creator.cc +14 -3
  277. package/third_party/quiche/quiche/quic/core/quic_packet_creator_test.cc +145 -2
  278. package/third_party/quiche/quiche/quic/core/quic_packets.cc +3 -1
  279. package/third_party/quiche/quiche/quic/core/quic_packets.h +4 -0
  280. package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager.cc +13 -11
  281. package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager.h +9 -0
  282. package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager_test.cc +6 -0
  283. package/third_party/quiche/quiche/quic/core/quic_session.cc +3 -2
  284. package/third_party/quiche/quiche/quic/core/quic_session.h +8 -3
  285. package/third_party/quiche/quiche/quic/core/quic_types.cc +18 -0
  286. package/third_party/quiche/quiche/quic/core/quic_types.h +3 -0
  287. package/third_party/quiche/quiche/quic/core/tls_chlo_extractor.cc +3 -0
  288. package/third_party/quiche/quiche/quic/core/tls_chlo_extractor.h +10 -0
  289. package/third_party/quiche/quiche/quic/test_tools/mock_quic_session_visitor.h +1 -1
  290. package/third_party/quiche/quiche/quic/test_tools/quic_test_utils.h +1 -1
  291. package/third_party/quiche/quiche/quic/test_tools/server_thread.cc +3 -2
  292. package/third_party/quiche/quiche/quic/test_tools/simple_session_notifier.cc +7 -1
  293. package/third_party/quiche/quiche/quic/test_tools/simple_session_notifier.h +3 -0
  294. package/third_party/quiche/quiche/quic/test_tools/simulator/quic_endpoint.h +4 -2
  295. package/certs/ca.cnf +0 -69
  296. package/certs/generate_certs.sh +0 -53
  297. package/certs/generate_certs_leaf.sh +0 -53
  298. package/certs/leaf.cnf +0 -24
  299. package/certs/readme.txt +0 -2
  300. package/third_party/quiche/build/BUILD.bazel +0 -7
@@ -56,8 +56,8 @@
56
56
 
57
57
  #include <openssl/asn1.h>
58
58
 
59
- #include <string.h>
60
59
  #include <limits.h>
60
+ #include <string.h>
61
61
 
62
62
  #include <openssl/bytestring.h>
63
63
  #include <openssl/err.h>
@@ -67,396 +67,372 @@
67
67
  #include "../internal.h"
68
68
 
69
69
 
70
- ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
71
- {
72
- return ASN1_STRING_dup(x);
70
+ ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) {
71
+ return ASN1_STRING_dup(x);
73
72
  }
74
73
 
75
- int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
76
- {
77
- /* Compare signs. */
78
- int neg = x->type & V_ASN1_NEG;
79
- if (neg != (y->type & V_ASN1_NEG)) {
80
- return neg ? -1 : 1;
81
- }
82
-
83
- int ret = ASN1_STRING_cmp(x, y);
84
- if (neg) {
85
- /* This could be |-ret|, but |ASN1_STRING_cmp| is not forbidden from
86
- * returning |INT_MIN|. */
87
- if (ret < 0) {
88
- return 1;
89
- } else if (ret > 0) {
90
- return -1;
91
- } else {
92
- return 0;
93
- }
74
+ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) {
75
+ // Compare signs.
76
+ int neg = x->type & V_ASN1_NEG;
77
+ if (neg != (y->type & V_ASN1_NEG)) {
78
+ return neg ? -1 : 1;
79
+ }
80
+
81
+ int ret = ASN1_STRING_cmp(x, y);
82
+ if (neg) {
83
+ // This could be |-ret|, but |ASN1_STRING_cmp| is not forbidden from
84
+ // returning |INT_MIN|.
85
+ if (ret < 0) {
86
+ return 1;
87
+ } else if (ret > 0) {
88
+ return -1;
89
+ } else {
90
+ return 0;
94
91
  }
92
+ }
95
93
 
96
- return ret;
94
+ return ret;
97
95
  }
98
96
 
99
- /* negate_twos_complement negates |len| bytes from |buf| in-place, interpreted
100
- * as a signed, big-endian two's complement value. */
101
- static void negate_twos_complement(uint8_t *buf, size_t len)
102
- {
103
- uint8_t borrow = 0;
104
- for (size_t i = len - 1; i < len; i--) {
105
- uint8_t t = buf[i];
106
- buf[i] = 0u - borrow - t;
107
- borrow |= t != 0;
108
- }
97
+ // negate_twos_complement negates |len| bytes from |buf| in-place, interpreted
98
+ // as a signed, big-endian two's complement value.
99
+ static void negate_twos_complement(uint8_t *buf, size_t len) {
100
+ uint8_t borrow = 0;
101
+ for (size_t i = len - 1; i < len; i--) {
102
+ uint8_t t = buf[i];
103
+ buf[i] = 0u - borrow - t;
104
+ borrow |= t != 0;
105
+ }
109
106
  }
110
107
 
111
108
  static int is_all_zeros(const uint8_t *in, size_t len) {
112
- for (size_t i = 0; i < len; i++) {
113
- if (in[i] != 0) {
114
- return 0;
115
- }
109
+ for (size_t i = 0; i < len; i++) {
110
+ if (in[i] != 0) {
111
+ return 0;
116
112
  }
117
- return 1;
113
+ }
114
+ return 1;
118
115
  }
119
116
 
120
- int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp)
121
- {
122
- if (in == NULL) {
123
- return 0;
124
- }
125
-
126
- /* |ASN1_INTEGER|s should be represented minimally, but it is possible to
127
- * construct invalid ones. Skip leading zeros so this does not produce an
128
- * invalid encoding or break invariants. */
129
- int start = 0;
130
- while (start < in->length && in->data[start] == 0) {
131
- start++;
132
- }
133
-
134
- int is_negative = (in->type & V_ASN1_NEG) != 0;
135
- int pad;
136
- if (start >= in->length) {
137
- /* Zero is represented as a single byte. */
138
- is_negative = 0;
139
- pad = 1;
140
- } else if (is_negative) {
141
- /* 0x80...01 through 0xff...ff have a two's complement of 0x7f...ff
142
- * through 0x00...01 and need an extra byte to be negative.
143
- * 0x01...00 through 0x80...00 have a two's complement of 0xfe...ff
144
- * through 0x80...00 and can be negated as-is. */
145
- pad = in->data[start] > 0x80 ||
146
- (in->data[start] == 0x80 &&
147
- !is_all_zeros(in->data + start + 1, in->length - start - 1));
148
- } else {
149
- /* If the high bit is set, the signed representation needs an extra
150
- * byte to be positive. */
151
- pad = (in->data[start] & 0x80) != 0;
152
- }
153
-
154
- if (in->length - start > INT_MAX - pad) {
155
- OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
156
- return 0;
157
- }
158
- int len = pad + in->length - start;
159
- assert(len > 0);
160
- if (outp == NULL) {
161
- return len;
162
- }
163
-
164
- if (pad) {
165
- (*outp)[0] = 0;
166
- }
167
- OPENSSL_memcpy(*outp + pad, in->data + start, in->length - start);
168
- if (is_negative) {
169
- negate_twos_complement(*outp, len);
170
- assert((*outp)[0] >= 0x80);
171
- } else {
172
- assert((*outp)[0] < 0x80);
173
- }
174
- *outp += len;
117
+ int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp) {
118
+ if (in == NULL) {
119
+ return 0;
120
+ }
121
+
122
+ // |ASN1_INTEGER|s should be represented minimally, but it is possible to
123
+ // construct invalid ones. Skip leading zeros so this does not produce an
124
+ // invalid encoding or break invariants.
125
+ int start = 0;
126
+ while (start < in->length && in->data[start] == 0) {
127
+ start++;
128
+ }
129
+
130
+ int is_negative = (in->type & V_ASN1_NEG) != 0;
131
+ int pad;
132
+ if (start >= in->length) {
133
+ // Zero is represented as a single byte.
134
+ is_negative = 0;
135
+ pad = 1;
136
+ } else if (is_negative) {
137
+ // 0x80...01 through 0xff...ff have a two's complement of 0x7f...ff
138
+ // through 0x00...01 and need an extra byte to be negative.
139
+ // 0x01...00 through 0x80...00 have a two's complement of 0xfe...ff
140
+ // through 0x80...00 and can be negated as-is.
141
+ pad = in->data[start] > 0x80 ||
142
+ (in->data[start] == 0x80 &&
143
+ !is_all_zeros(in->data + start + 1, in->length - start - 1));
144
+ } else {
145
+ // If the high bit is set, the signed representation needs an extra
146
+ // byte to be positive.
147
+ pad = (in->data[start] & 0x80) != 0;
148
+ }
149
+
150
+ if (in->length - start > INT_MAX - pad) {
151
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
152
+ return 0;
153
+ }
154
+ int len = pad + in->length - start;
155
+ assert(len > 0);
156
+ if (outp == NULL) {
175
157
  return len;
158
+ }
159
+
160
+ if (pad) {
161
+ (*outp)[0] = 0;
162
+ }
163
+ OPENSSL_memcpy(*outp + pad, in->data + start, in->length - start);
164
+ if (is_negative) {
165
+ negate_twos_complement(*outp, len);
166
+ assert((*outp)[0] >= 0x80);
167
+ } else {
168
+ assert((*outp)[0] < 0x80);
169
+ }
170
+ *outp += len;
171
+ return len;
176
172
  }
177
173
 
178
174
  ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
179
- long len)
180
- {
181
- /*
182
- * This function can handle lengths up to INT_MAX - 1, but the rest of the
183
- * legacy ASN.1 code mixes integer types, so avoid exposing it to
184
- * ASN1_INTEGERS with larger lengths.
185
- */
186
- if (len < 0 || len > INT_MAX / 2) {
187
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
188
- return NULL;
189
- }
190
-
191
- CBS cbs;
192
- CBS_init(&cbs, *inp, (size_t)len);
193
- int is_negative;
194
- if (!CBS_is_valid_asn1_integer(&cbs, &is_negative)) {
195
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
196
- return NULL;
197
- }
198
-
199
- ASN1_INTEGER *ret = NULL;
200
- if (out == NULL || *out == NULL) {
201
- ret = ASN1_INTEGER_new();
202
- if (ret == NULL) {
203
- return NULL;
204
- }
205
- } else {
206
- ret = *out;
207
- }
208
-
209
- /* Convert to |ASN1_INTEGER|'s sign-and-magnitude representation. First,
210
- * determine the size needed for a minimal result. */
211
- if (is_negative) {
212
- /* 0xff00...01 through 0xff7f..ff have a two's complement of 0x00ff...ff
213
- * through 0x000100...001 and need one leading zero removed. 0x8000...00
214
- * through 0xff00...00 have a two's complement of 0x8000...00 through
215
- * 0x0100...00 and will be minimally-encoded as-is. */
216
- if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0xff &&
217
- !is_all_zeros(CBS_data(&cbs) + 1, CBS_len(&cbs) - 1)) {
218
- CBS_skip(&cbs, 1);
219
- }
220
- } else {
221
- /* Remove the leading zero byte, if any. */
222
- if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0x00) {
223
- CBS_skip(&cbs, 1);
224
- }
225
- }
226
-
227
- if (!ASN1_STRING_set(ret, CBS_data(&cbs), CBS_len(&cbs))) {
228
- goto err;
229
- }
230
-
231
- if (is_negative) {
232
- ret->type = V_ASN1_NEG_INTEGER;
233
- negate_twos_complement(ret->data, ret->length);
234
- } else {
235
- ret->type = V_ASN1_INTEGER;
236
- }
175
+ long len) {
176
+ // This function can handle lengths up to INT_MAX - 1, but the rest of the
177
+ // legacy ASN.1 code mixes integer types, so avoid exposing it to
178
+ // ASN1_INTEGERS with larger lengths.
179
+ if (len < 0 || len > INT_MAX / 2) {
180
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
181
+ return NULL;
182
+ }
237
183
 
238
- /* The value should be minimally-encoded. */
239
- assert(ret->length == 0 || ret->data[0] != 0);
240
- /* Zero is not negative. */
241
- assert(!is_negative || ret->length > 0);
184
+ CBS cbs;
185
+ CBS_init(&cbs, *inp, (size_t)len);
186
+ int is_negative;
187
+ if (!CBS_is_valid_asn1_integer(&cbs, &is_negative)) {
188
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
189
+ return NULL;
190
+ }
242
191
 
243
- *inp += len;
244
- if (out != NULL) {
245
- *out = ret;
246
- }
247
- return ret;
192
+ ASN1_INTEGER *ret = NULL;
193
+ if (out == NULL || *out == NULL) {
194
+ ret = ASN1_INTEGER_new();
195
+ if (ret == NULL) {
196
+ return NULL;
197
+ }
198
+ } else {
199
+ ret = *out;
200
+ }
201
+
202
+ // Convert to |ASN1_INTEGER|'s sign-and-magnitude representation. First,
203
+ // determine the size needed for a minimal result.
204
+ if (is_negative) {
205
+ // 0xff00...01 through 0xff7f..ff have a two's complement of 0x00ff...ff
206
+ // through 0x000100...001 and need one leading zero removed. 0x8000...00
207
+ // through 0xff00...00 have a two's complement of 0x8000...00 through
208
+ // 0x0100...00 and will be minimally-encoded as-is.
209
+ if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0xff &&
210
+ !is_all_zeros(CBS_data(&cbs) + 1, CBS_len(&cbs) - 1)) {
211
+ CBS_skip(&cbs, 1);
212
+ }
213
+ } else {
214
+ // Remove the leading zero byte, if any.
215
+ if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0x00) {
216
+ CBS_skip(&cbs, 1);
217
+ }
218
+ }
219
+
220
+ if (!ASN1_STRING_set(ret, CBS_data(&cbs), CBS_len(&cbs))) {
221
+ goto err;
222
+ }
223
+
224
+ if (is_negative) {
225
+ ret->type = V_ASN1_NEG_INTEGER;
226
+ negate_twos_complement(ret->data, ret->length);
227
+ } else {
228
+ ret->type = V_ASN1_INTEGER;
229
+ }
230
+
231
+ // The value should be minimally-encoded.
232
+ assert(ret->length == 0 || ret->data[0] != 0);
233
+ // Zero is not negative.
234
+ assert(!is_negative || ret->length > 0);
235
+
236
+ *inp += len;
237
+ if (out != NULL) {
238
+ *out = ret;
239
+ }
240
+ return ret;
248
241
 
249
- err:
250
- if (ret != NULL && (out == NULL || *out != ret)) {
251
- ASN1_INTEGER_free(ret);
252
- }
253
- return NULL;
242
+ err:
243
+ if (ret != NULL && (out == NULL || *out != ret)) {
244
+ ASN1_INTEGER_free(ret);
245
+ }
246
+ return NULL;
254
247
  }
255
248
 
256
- int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
257
- {
258
- if (v >= 0) {
259
- return ASN1_INTEGER_set_uint64(a, (uint64_t) v);
260
- }
249
+ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) {
250
+ if (v >= 0) {
251
+ return ASN1_INTEGER_set_uint64(a, (uint64_t)v);
252
+ }
261
253
 
262
- if (!ASN1_INTEGER_set_uint64(a, 0 - (uint64_t) v)) {
263
- return 0;
264
- }
254
+ if (!ASN1_INTEGER_set_uint64(a, 0 - (uint64_t)v)) {
255
+ return 0;
256
+ }
265
257
 
266
- a->type = V_ASN1_NEG_INTEGER;
267
- return 1;
258
+ a->type = V_ASN1_NEG_INTEGER;
259
+ return 1;
268
260
  }
269
261
 
270
- int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
271
- {
272
- if (v >= 0) {
273
- return ASN1_ENUMERATED_set_uint64(a, (uint64_t) v);
274
- }
262
+ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) {
263
+ if (v >= 0) {
264
+ return ASN1_ENUMERATED_set_uint64(a, (uint64_t)v);
265
+ }
275
266
 
276
- if (!ASN1_ENUMERATED_set_uint64(a, 0 - (uint64_t) v)) {
277
- return 0;
278
- }
267
+ if (!ASN1_ENUMERATED_set_uint64(a, 0 - (uint64_t)v)) {
268
+ return 0;
269
+ }
279
270
 
280
- a->type = V_ASN1_NEG_ENUMERATED;
281
- return 1;
271
+ a->type = V_ASN1_NEG_ENUMERATED;
272
+ return 1;
282
273
  }
283
274
 
284
- static int asn1_string_set_uint64(ASN1_STRING *out, uint64_t v, int type)
285
- {
286
- uint8_t buf[sizeof(uint64_t)];
287
- CRYPTO_store_u64_be(buf, v);
288
- size_t leading_zeros;
289
- for (leading_zeros = 0; leading_zeros < sizeof(buf); leading_zeros++) {
290
- if (buf[leading_zeros] != 0) {
291
- break;
292
- }
293
- }
294
-
295
- if (!ASN1_STRING_set(out, buf + leading_zeros,
296
- sizeof(buf) - leading_zeros)) {
297
- return 0;
298
- }
299
- out->type = type;
300
- return 1;
275
+ static int asn1_string_set_uint64(ASN1_STRING *out, uint64_t v, int type) {
276
+ uint8_t buf[sizeof(uint64_t)];
277
+ CRYPTO_store_u64_be(buf, v);
278
+ size_t leading_zeros;
279
+ for (leading_zeros = 0; leading_zeros < sizeof(buf); leading_zeros++) {
280
+ if (buf[leading_zeros] != 0) {
281
+ break;
282
+ }
283
+ }
284
+
285
+ if (!ASN1_STRING_set(out, buf + leading_zeros, sizeof(buf) - leading_zeros)) {
286
+ return 0;
287
+ }
288
+ out->type = type;
289
+ return 1;
301
290
  }
302
291
 
303
- int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v)
304
- {
305
- return asn1_string_set_uint64(out, v, V_ASN1_INTEGER);
292
+ int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v) {
293
+ return asn1_string_set_uint64(out, v, V_ASN1_INTEGER);
306
294
  }
307
295
 
308
- int ASN1_ENUMERATED_set_uint64(ASN1_ENUMERATED *out, uint64_t v)
309
- {
310
- return asn1_string_set_uint64(out, v, V_ASN1_ENUMERATED);
296
+ int ASN1_ENUMERATED_set_uint64(ASN1_ENUMERATED *out, uint64_t v) {
297
+ return asn1_string_set_uint64(out, v, V_ASN1_ENUMERATED);
311
298
  }
312
299
 
313
300
  static int asn1_string_get_abs_uint64(uint64_t *out, const ASN1_STRING *a,
314
- int type)
315
- {
316
- if ((a->type & ~V_ASN1_NEG) != type) {
317
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
318
- return 0;
319
- }
320
- uint8_t buf[sizeof(uint64_t)] = {0};
321
- if (a->length > (int)sizeof(buf)) {
322
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
323
- return 0;
324
- }
325
- OPENSSL_memcpy(buf + sizeof(buf) - a->length, a->data, a->length);
326
- *out = CRYPTO_load_u64_be(buf);
327
- return 1;
301
+ int type) {
302
+ if ((a->type & ~V_ASN1_NEG) != type) {
303
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
304
+ return 0;
305
+ }
306
+ uint8_t buf[sizeof(uint64_t)] = {0};
307
+ if (a->length > (int)sizeof(buf)) {
308
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
309
+ return 0;
310
+ }
311
+ OPENSSL_memcpy(buf + sizeof(buf) - a->length, a->data, a->length);
312
+ *out = CRYPTO_load_u64_be(buf);
313
+ return 1;
328
314
  }
329
315
 
330
- static int asn1_string_get_uint64(uint64_t *out, const ASN1_STRING *a, int type)
331
- {
332
- if (!asn1_string_get_abs_uint64(out, a, type)) {
333
- return 0;
334
- }
335
- if (a->type & V_ASN1_NEG) {
336
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
337
- return 0;
338
- }
339
- return 1;
316
+ static int asn1_string_get_uint64(uint64_t *out, const ASN1_STRING *a,
317
+ int type) {
318
+ if (!asn1_string_get_abs_uint64(out, a, type)) {
319
+ return 0;
320
+ }
321
+ if (a->type & V_ASN1_NEG) {
322
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
323
+ return 0;
324
+ }
325
+ return 1;
340
326
  }
341
327
 
342
- int ASN1_INTEGER_get_uint64(uint64_t *out, const ASN1_INTEGER *a)
343
- {
344
- return asn1_string_get_uint64(out, a, V_ASN1_INTEGER);
328
+ int ASN1_INTEGER_get_uint64(uint64_t *out, const ASN1_INTEGER *a) {
329
+ return asn1_string_get_uint64(out, a, V_ASN1_INTEGER);
345
330
  }
346
331
 
347
- int ASN1_ENUMERATED_get_uint64(uint64_t *out, const ASN1_ENUMERATED *a)
348
- {
349
- return asn1_string_get_uint64(out, a, V_ASN1_ENUMERATED);
332
+ int ASN1_ENUMERATED_get_uint64(uint64_t *out, const ASN1_ENUMERATED *a) {
333
+ return asn1_string_get_uint64(out, a, V_ASN1_ENUMERATED);
350
334
  }
351
335
 
352
- static long asn1_string_get_long(const ASN1_STRING *a, int type)
353
- {
354
- if (a == NULL) {
355
- return 0;
356
- }
357
-
358
- uint64_t v;
359
- if (!asn1_string_get_abs_uint64(&v, a, type)) {
360
- goto err;
361
- }
362
-
363
- int64_t i64;
364
- int fits_in_i64;
365
- /* Check |v != 0| to handle manually-constructed negative zeros. */
366
- if ((a->type & V_ASN1_NEG) && v != 0) {
367
- i64 = (int64_t)(0u - v);
368
- fits_in_i64 = i64 < 0;
369
- } else {
370
- i64 = (int64_t)v;
371
- fits_in_i64 = i64 >= 0;
372
- }
373
- OPENSSL_STATIC_ASSERT(sizeof(long) <= sizeof(int64_t), "long is too big");
374
-
375
- if (fits_in_i64 && LONG_MIN <= i64 && i64 <= LONG_MAX) {
376
- return (long)i64;
377
- }
336
+ static long asn1_string_get_long(const ASN1_STRING *a, int type) {
337
+ if (a == NULL) {
338
+ return 0;
339
+ }
340
+
341
+ uint64_t v;
342
+ if (!asn1_string_get_abs_uint64(&v, a, type)) {
343
+ goto err;
344
+ }
345
+
346
+ int64_t i64;
347
+ int fits_in_i64;
348
+ // Check |v != 0| to handle manually-constructed negative zeros.
349
+ if ((a->type & V_ASN1_NEG) && v != 0) {
350
+ i64 = (int64_t)(0u - v);
351
+ fits_in_i64 = i64 < 0;
352
+ } else {
353
+ i64 = (int64_t)v;
354
+ fits_in_i64 = i64 >= 0;
355
+ }
356
+ OPENSSL_STATIC_ASSERT(sizeof(long) <= sizeof(int64_t), "long is too big");
357
+
358
+ if (fits_in_i64 && LONG_MIN <= i64 && i64 <= LONG_MAX) {
359
+ return (long)i64;
360
+ }
378
361
 
379
362
  err:
380
- /* This function's return value does not distinguish overflow from -1. */
381
- ERR_clear_error();
382
- return -1;
363
+ // This function's return value does not distinguish overflow from -1.
364
+ ERR_clear_error();
365
+ return -1;
383
366
  }
384
367
 
385
- long ASN1_INTEGER_get(const ASN1_INTEGER *a)
386
- {
387
- return asn1_string_get_long(a, V_ASN1_INTEGER);
368
+ long ASN1_INTEGER_get(const ASN1_INTEGER *a) {
369
+ return asn1_string_get_long(a, V_ASN1_INTEGER);
388
370
  }
389
371
 
390
- long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
391
- {
392
- return asn1_string_get_long(a, V_ASN1_ENUMERATED);
372
+ long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a) {
373
+ return asn1_string_get_long(a, V_ASN1_ENUMERATED);
393
374
  }
394
375
 
395
376
  static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
396
- int type)
397
- {
398
- ASN1_INTEGER *ret;
399
- if (ai == NULL) {
400
- ret = ASN1_STRING_type_new(type);
401
- } else {
402
- ret = ai;
403
- }
404
- if (ret == NULL) {
405
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
406
- goto err;
407
- }
408
-
409
- if (BN_is_negative(bn) && !BN_is_zero(bn)) {
410
- ret->type = type | V_ASN1_NEG;
411
- } else {
412
- ret->type = type;
413
- }
414
-
415
- int len = BN_num_bytes(bn);
416
- if (!ASN1_STRING_set(ret, NULL, len) ||
417
- !BN_bn2bin_padded(ret->data, len, bn)) {
418
- goto err;
419
- }
420
- return ret;
377
+ int type) {
378
+ ASN1_INTEGER *ret;
379
+ if (ai == NULL) {
380
+ ret = ASN1_STRING_type_new(type);
381
+ } else {
382
+ ret = ai;
383
+ }
384
+ if (ret == NULL) {
385
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
386
+ goto err;
387
+ }
388
+
389
+ if (BN_is_negative(bn) && !BN_is_zero(bn)) {
390
+ ret->type = type | V_ASN1_NEG;
391
+ } else {
392
+ ret->type = type;
393
+ }
394
+
395
+ int len = BN_num_bytes(bn);
396
+ if (!ASN1_STRING_set(ret, NULL, len) ||
397
+ !BN_bn2bin_padded(ret->data, len, bn)) {
398
+ goto err;
399
+ }
400
+ return ret;
421
401
 
422
- err:
423
- if (ret != ai) {
424
- ASN1_STRING_free(ret);
425
- }
426
- return NULL;
402
+ err:
403
+ if (ret != ai) {
404
+ ASN1_STRING_free(ret);
405
+ }
406
+ return NULL;
427
407
  }
428
408
 
429
- ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
430
- {
431
- return bn_to_asn1_string(bn, ai, V_ASN1_INTEGER);
409
+ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) {
410
+ return bn_to_asn1_string(bn, ai, V_ASN1_INTEGER);
432
411
  }
433
412
 
434
- ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
435
- {
436
- return bn_to_asn1_string(bn, ai, V_ASN1_ENUMERATED);
413
+ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai) {
414
+ return bn_to_asn1_string(bn, ai, V_ASN1_ENUMERATED);
437
415
  }
438
416
 
439
- static BIGNUM *asn1_string_to_bn(const ASN1_STRING *ai, BIGNUM *bn, int type)
440
- {
441
- if ((ai->type & ~V_ASN1_NEG) != type) {
442
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
443
- return NULL;
444
- }
445
-
446
- BIGNUM *ret;
447
- if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
448
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BN_LIB);
449
- else if (ai->type & V_ASN1_NEG)
450
- BN_set_negative(ret, 1);
451
- return (ret);
417
+ static BIGNUM *asn1_string_to_bn(const ASN1_STRING *ai, BIGNUM *bn, int type) {
418
+ if ((ai->type & ~V_ASN1_NEG) != type) {
419
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
420
+ return NULL;
421
+ }
422
+
423
+ BIGNUM *ret;
424
+ if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL) {
425
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BN_LIB);
426
+ } else if (ai->type & V_ASN1_NEG) {
427
+ BN_set_negative(ret, 1);
428
+ }
429
+ return ret;
452
430
  }
453
431
 
454
- BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
455
- {
456
- return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);
432
+ BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn) {
433
+ return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);
457
434
  }
458
435
 
459
- BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
460
- {
461
- return asn1_string_to_bn(ai, bn, V_ASN1_ENUMERATED);
436
+ BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn) {
437
+ return asn1_string_to_bn(ai, bn, V_ASN1_ENUMERATED);
462
438
  }