1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ANONYMOUS_TOKENS_CPP_CLIENT_ANONYMOUS_TOKENS_PUBLIC_KEY_CLIENT_H_ 16 #define ANONYMOUS_TOKENS_CPP_CLIENT_ANONYMOUS_TOKENS_PUBLIC_KEY_CLIENT_H_ 17 18 #include <cstddef> 19 #include <memory> 20 #include <vector> 21 22 #include "absl/status/statusor.h" 23 #include "absl/time/clock.h" 24 #include "absl/time/time.h" 25 #include "absl/types/optional.h" 26 #include "anonymous_tokens/proto/anonymous_tokens.pb.h" 27 28 29 namespace anonymous_tokens { 30 31 // This class generates AnonymousTokens Public Key(s) Get request and processes 32 // the response. 33 // 34 // Each execution of the AnonymousTokens Public Key(s) Get protocol requires a 35 // new instance of the AnonymousTokensPublicKeyGetClient. 36 // 37 // This class is not thread-safe. 38 class AnonymousTokensPublicKeysGetClient { 39 public: 40 // AnonymousTokensPublicKeyGetClient is neither copyable nor copy assignable. 41 AnonymousTokensPublicKeysGetClient( 42 const AnonymousTokensPublicKeysGetClient&) = delete; 43 AnonymousTokensPublicKeysGetClient& operator=( 44 const AnonymousTokensPublicKeysGetClient&) = delete; 45 46 // Creates AnonymousTokensPublicKeyGetClient. 47 static absl::StatusOr<std::unique_ptr<AnonymousTokensPublicKeysGetClient>> 48 Create(); 49 50 // This method is used to create requests to retrieve public key(s) from the 51 // server. 52 // 53 // Key version defaults to 0. A value of 0 means that all key(s) for use_case 54 // that adhere to the validity time window in the request, will be returned. 55 // 56 // key_validity_start_time defaults to absl::Now(). key_validity_start_time 57 // indicates that the public key(s) expected in the response must have their 58 // valid period start time before or at this time. 59 // 60 // key_validity_end_time defaults to null which indicates that only 61 // indefinitely valid key(s) must be returned. However if, this time is set, 62 // the key(s) returned must expire before or at this indicated time. 63 absl::StatusOr<AnonymousTokensPublicKeysGetRequest> 64 CreateAnonymousTokensPublicKeysGetRequest( 65 AnonymousTokensUseCase use_case, int64_t key_version = 0, 66 absl::Time key_validity_start_time = absl::Now(), 67 absl::optional<absl::Time> key_validity_end_time = absl::nullopt); 68 69 // This method is used to process the AnonymousTokensPublicKeysGetResponse 70 // sent by the public key server. 71 absl::StatusOr<std::vector<RSABlindSignaturePublicKey>> 72 ProcessAnonymousTokensRSAPublicKeysGetResponse( 73 const AnonymousTokensPublicKeysGetResponse& rsa_public_key_get_response); 74 75 private: 76 AnonymousTokensPublicKeysGetClient() = default; 77 78 // Request created by CreateAnonymousTokensPublicKeysGetRequest is stored here 79 // so that it can be used in processing of the server response. 80 AnonymousTokensPublicKeysGetRequest public_key_request_; 81 }; 82 83 } // namespace anonymous_tokens 84 85 86 #endif // ANONYMOUS_TOKENS_CPP_CLIENT_ANONYMOUS_TOKENS_PUBLIC_KEY_CLIENT_H_ 87