1 /* 2 * Copyright 2018 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef FCP_SECAGG_CLIENT_SECAGG_CLIENT_ALIVE_BASE_STATE_H_ 18 #define FCP_SECAGG_CLIENT_SECAGG_CLIENT_ALIVE_BASE_STATE_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "fcp/secagg/client/secagg_client_state.h" 24 #include "fcp/secagg/client/send_to_server_interface.h" 25 #include "fcp/secagg/client/state_transition_listener_interface.h" 26 #include "fcp/secagg/shared/async_abort.h" 27 28 namespace fcp { 29 namespace secagg { 30 31 // Abstract base class containing code used by all SecAggClientStates where the 32 // client is still alive and online, i.e. non-terminal states. 33 34 class SecAggClientAliveBaseState : public SecAggClientState { 35 public: 36 ~SecAggClientAliveBaseState() override = default; 37 38 StatusOr<std::unique_ptr<SecAggClientState> > Abort( 39 const std::string& reason) override; 40 41 protected: 42 // SecAggClientAliveBaseState should never be instantiated directly. 43 explicit SecAggClientAliveBaseState( 44 std::unique_ptr<SendToServerInterface> sender, 45 std::unique_ptr<StateTransitionListenerInterface> transition_listener, 46 ClientState state, AsyncAbort* async_abort = nullptr); 47 48 // Method to be used internally by child SecAggClient*State classes, called 49 // when an abort is required by the protocol. Sends an abort message to the 50 // server, then constructs and returns an abort state. 51 std::unique_ptr<SecAggClientState> AbortAndNotifyServer( 52 const std::string& reason); 53 54 AsyncAbort* async_abort_; // Owned by state owner. 55 }; 56 57 } // namespace secagg 58 } // namespace fcp 59 60 #endif // FCP_SECAGG_CLIENT_SECAGG_CLIENT_ALIVE_BASE_STATE_H_ 61