| // Copyright 2026 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| // |
| |
| #ifndef THIRD_PARTY_CREDENTIO_JUMBF_URI_H_ |
| #define THIRD_PARTY_CREDENTIO_JUMBF_URI_H_ |
| |
| #include <string> |
| |
| #include "absl/base/nullability.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/string_view.h" |
| #include "jumbf/box.h" |
| |
| namespace jumbf { |
| |
| class UriResolver { |
| public: |
| // Creates a new UriResolver where the root node has a single child. |
| static UriResolver WithSingleRootChild(const SuperBox* root_child); |
| |
| // Resolves a JUMBF URI in one of these forms to an absolute path: |
| // * `self#jumbf=/label1/label2/label3` --> `/label1/label2/label3` |
| // * `self#jumbf=label3/label4` --> `/label1/label2/label3/label4` |
| // (if `current_path` is `/label1/label2`) |
| // |
| // `current_path` must be an absolute path (e.g., `/label1/label2`). |
| static absl::StatusOr<std::string> GetAbsolutePathFromUri( |
| absl::string_view uri, absl::string_view current_path); |
| |
| // Resolves a path in one of these forms to an absolute path: |
| // * `/label1/label2/label3` -- absolute path |
| // * `label3/label4` -- path gets `{current_path}/` prepended |
| // `current_path` must be an absolute path (e.g., `/label1/label2`). |
| static std::string GetAbsolutePath(absl::string_view path, |
| absl::string_view current_path); |
| |
| // Resolves the given absolute path (produced by GetAbsolutePathFromUri() or |
| // GetAbsolutePath()) to a SuperBox. No "." or ".." path components are |
| // allowed. |
| absl::StatusOr<const SuperBox*> ResolvePath( |
| absl::string_view absolute_path) const; |
| |
| private: |
| UriResolver(const SuperBox* absl_nonnull root_box, std::string root_path); |
| |
| const SuperBox& root_box_; |
| std::string root_path_; // Path to root_box_, with trailing slash. |
| }; |
| |
| } // namespace jumbf |
| |
| #endif // THIRD_PARTY_CREDENTIO_JUMBF_URI_H_ |