1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_HTTP_HTTP_COOKIE_INDICES_H_ 6 #define NET_HTTP_HTTP_COOKIE_INDICES_H_ 7 8 #include <optional> 9 #include <string> 10 #include <utility> 11 #include <vector> 12 13 #include "base/containers/span.h" 14 #include "net/base/net_export.h" 15 16 namespace net { 17 18 class HttpResponseHeaders; 19 20 // Parse the Cookie-Indices response header, if present (even if the Vary header 21 // is not). 22 // 23 // Returns an empty optional if the header was absent, not a valid structured 24 // list, or contained an invalid/unrecognized item. 25 NET_EXPORT std::optional<std::vector<std::string>> ParseCookieIndices( 26 const HttpResponseHeaders& headers); 27 28 // Processes the Cookie-Indices value (as presented above) and the cookies 29 // found in a request to produce a compact hash that can be compared later. 30 // Currently this is done with SHA-256, which is a cryptographic hash function. 31 // Comparing hashes computed with different |cookie_indices| arrays is 32 // unspecified -- don't do it. 33 // 34 // |cookie_indices| must be sorted and unique; |cookies| may appear in any 35 // order. 36 using CookieIndicesHash = std::array<uint8_t, 32>; 37 NET_EXPORT CookieIndicesHash HashCookieIndices( 38 base::span<const std::string> cookie_indices, 39 base::span<const std::pair<std::string, std::string>> cookies); 40 41 } // namespace net 42 43 #endif // NET_HTTP_HTTP_COOKIE_INDICES_H_ 44