| // Copyright 2025 The Chromium Authors | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #ifndef REMOTING_BASE_INSTANCE_IDENTITY_TOKEN_H_ | |
| #define REMOTING_BASE_INSTANCE_IDENTITY_TOKEN_H_ | |
| #include <optional> | |
| #include <ostream> | |
| #include <string> | |
| #include <string_view> | |
| #include "base/values.h" | |
| namespace remoting { | |
| // Represents a decoded JWT retrieved from the Compute Engine metadata server. | |
| class InstanceIdentityToken final { | |
| public: | |
| // Returns a new instance if |jwt| is well-formed, otherwise nullopt. Note | |
| // that |jwt| could be expired and the Create() function will still succeed as | |
| // long as all of the required fields are present. | |
| static std::optional<InstanceIdentityToken> Create(std::string_view jwt); | |
| InstanceIdentityToken(InstanceIdentityToken&& other) = default; | |
| InstanceIdentityToken& operator=(InstanceIdentityToken&& other) = default; | |
| InstanceIdentityToken(const InstanceIdentityToken&) = delete; | |
| InstanceIdentityToken& operator=(const InstanceIdentityToken&) = delete; | |
| ~InstanceIdentityToken(); | |
| const base::DictValue& header() const { return header_; } | |
| const base::DictValue& payload() const { return payload_; } | |
| private: | |
| InstanceIdentityToken(base::DictValue header, base::DictValue payload); | |
| base::DictValue header_; | |
| base::DictValue payload_; | |
| }; | |
| std::ostream& operator<<(std::ostream& out, const InstanceIdentityToken& token); | |
| } // namespace remoting | |
| #endif // REMOTING_BASE_INSTANCE_IDENTITY_TOKEN_H_ |