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 namespace anonymous_tokens { 29 30 // This class generates AnonymousTokens Public Key(s) Get request and processes 31 // the response. 32 // 33 // Each execution of the AnonymousTokens Public Key(s) Get protocol requires a 34 // new instance of the AnonymousTokensPublicKeyGetClient. 35 // 36 // This class is not thread-safe. 37 class AnonymousTokensPublicKeysGetClient { 38 public: 39 // AnonymousTokensPublicKeyGetClient is neither copyable nor copy assignable. 40 AnonymousTokensPublicKeysGetClient( 41 const AnonymousTokensPublicKeysGetClient&) = delete; 42 AnonymousTokensPublicKeysGetClient& operator=( 43 const AnonymousTokensPublicKeysGetClient&) = delete; 44 45 // Creates AnonymousTokensPublicKeyGetClient. 46 static absl::StatusOr<std::unique_ptr<AnonymousTokensPublicKeysGetClient>> 47 Create(); 48 49 // This method is used to create requests to retrieve public key(s) from the 50 // server. 51 // 52 // Key version defaults to 0. A value of 0 means that all key(s) for use_case 53 // that adhere to the validity time window in the request, will be returned. 54 // 55 // key_validity_start_time defaults to absl::Now(). key_validity_start_time 56 // indicates that the public key(s) expected in the response must have their 57 // valid period start time before or at this time. 58 // 59 // key_validity_end_time defaults to null which indicates that only 60 // indefinitely valid key(s) must be returned. However if, this time is set, 61 // the key(s) returned must expire before or at this indicated time. 62 absl::StatusOr<AnonymousTokensPublicKeysGetRequest> 63 CreateAnonymousTokensPublicKeysGetRequest( 64 AnonymousTokensUseCase use_case, int64_t key_version = 0, 65 absl::Time key_validity_start_time = absl::Now(), 66 absl::optional<absl::Time> key_validity_end_time = absl::nullopt); 67 68 // This method is used to process the AnonymousTokensPublicKeysGetResponse 69 // sent by the public key server. 70 absl::StatusOr<std::vector<RSABlindSignaturePublicKey>> 71 ProcessAnonymousTokensRSAPublicKeysGetResponse( 72 const AnonymousTokensPublicKeysGetResponse& rsa_public_key_get_response); 73 74 private: 75 AnonymousTokensPublicKeysGetClient() = default; 76 77 // Request created by CreateAnonymousTokensPublicKeysGetRequest is stored here 78 // so that it can be used in processing of the server response. 79 AnonymousTokensPublicKeysGetRequest public_key_request_; 80 }; 81 82 } // namespace anonymous_tokens 83 84 #endif // ANONYMOUS_TOKENS_CPP_CLIENT_ANONYMOUS_TOKENS_PUBLIC_KEY_CLIENT_H_ 85