@@ -23,77 +23,6 @@ namespace cloud {
2323namespace storage {
2424GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2525
26- namespace internal {
27-
28- Status ValidateObjectContext (std::string const & key, std::string const & value) {
29- // Helper lambda to validate shared rules for both keys and values
30- auto validate_component = [](std::string const & str,
31- char const * name) -> Status {
32- // The GCS spec requires each object context key / value to
33- // contain 1 - 256 UTF-8 code units. Since each UTF-8 code unit is
34- // equivalent to 1 byte, we use std::string::size() to check the
35- // number of bytes.
36- if (str.empty () || str.size () > 256 ) {
37- return Status (StatusCode::kInvalidArgument ,
38- std::string (" Object context " ) + name +
39- " must be between 1 and 256 UTF-8 code units." );
40- }
41- if (!std::isalnum (static_cast <unsigned char >(str.front ()))) {
42- return Status (StatusCode::kInvalidArgument ,
43- std::string (" Object context " ) + name +
44- " must begin with an alphanumeric character." );
45- }
46- if (str.find_first_of (" '\"\\ /" ) != std::string::npos) {
47- return Status (StatusCode::kInvalidArgument ,
48- std::string (" Object context " ) + name +
49- " cannot contain ', \" , \\ , or /." );
50- }
51- return Status ();
52- };
53-
54- auto status = validate_component (key, " keys" );
55- if (!status.ok ()) return status;
56-
57- status = validate_component (value, " values" );
58- if (!status.ok ()) return status;
59-
60- // Rule specific to keys: Cannot begin with 'goog' (case-insensitive)
61- if (key.size () >= 4 ) {
62- std::string prefix = key.substr (0 , 4 );
63- std::transform (prefix.begin (), prefix.end (), prefix.begin (),
64- [](unsigned char c) { return std::tolower (c); });
65-
66- if (prefix == " goog" ) {
67- return Status (
68- StatusCode::kInvalidArgument ,
69- " Object context keys cannot begin with 'goog' (case-insensitive)." );
70- }
71- }
72- return Status ();
73- }
74-
75- Status ValidateObjectContextsAggregate (ObjectContexts const & contexts) {
76- // Validate each individual key-value pair and calculate aggregate size.
77- for (auto const & kv : contexts.custom ()) {
78- auto status = ValidateObjectContext (kv.first , kv.second .value );
79- if (!status.ok ()) return status;
80- }
81-
82- // Rule: Count limited to 50.
83- if (contexts.custom ().size () > 50 ) {
84- return Status (StatusCode::kInvalidArgument ,
85- " Object contexts are limited to 50 entries per object." );
86- }
87-
88- // Note: The API limits the aggregate size to 25 KiB (25,600 bytes).
89- // With a max of 50 items and a max of 256 bytes per key and value,
90- // the maximum possible size is exactly 50 * (256 + 256) = 25,600 bytes.
91- // Therefore, an explicit aggregate size check is mathematically redundant.
92- return Status ();
93- }
94-
95- } // namespace internal
96-
9726std::ostream& operator <<(std::ostream& os,
9827 ObjectCustomContextPayload const & rhs) {
9928 return os << " ObjectCustomContextPayload{value=" << rhs.value
0 commit comments