Turi Create  4.0
authentication_base.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef CPPIPC_COMMON_AUTHENTICATION_BASE_HPP
7 #define CPPIPC_COMMON_AUTHENTICATION_BASE_HPP
8 #include <string>
9 #include <core/system/cppipc/common/message_types.hpp>
10 namespace cppipc {
11 
12 /**
13  * Base class for all authentication method implementations.
14  *
15  * The class implements a few basic functions to attach and validate messages
16  * sent between the client and the server. Messages sent from the client to
17  * the server are \ref call_message objects. Messages sent from the server
18  * to the client (in response to a call message) are \ref reply_message
19  * objects.
20  *
21  * \ref authentication_base::apply_auth(call_message& msg) is called on the
22  * client side to attach authentication information to the message. When the
23  * server receives the message,
24  * \ref authentication_base::validate_auth(call_message& msg) is called on the
25  * server side to validate the message. If this function returns false, the
26  * server discards the message.
27  * The server then replies with a \ref reply_message and the function
28  * \ref authentication_base::apply_auth(reply_message& msg) is called on the
29  * server side to attach authentication information to the message. When the
30  * client receives the message,
31  * \ref authentication_base::validate_auth(reply_message& msg) is called on the
32  * client side to validate the message. If this function returns false, the
33  * function call is marked as failed.
34  *
35  * All of the implemented functions must be reentrant, and must not assume
36  * synchronicity. (i.e. apply_auth can be called on the client side many
37  * times in succession).
38  *
39  * Finally, authentication methods should be designed to be "stackable" with
40  * other authentication methods. i.e. I should be able to apply two different
41  * types of authentication methods on top of each other.
42  */
44  public:
45  virtual inline ~authentication_base(){}
46 
47  /**
48  * Attaches the authentication information to a message sent
49  * from the client to the server. This function must be reentrant.
50  */
51  virtual void apply_auth(call_message& msg) = 0;
52 
53  /**
54  * Attaches the authentication information to a message sent
55  * from the server to the client. This function must be reentrant.
56  */
57  virtual void apply_auth(reply_message& msg) = 0;
58 
59  /**
60  * Validates a message received on the server from a client. This function
61  * must be reentrant. If the function returns true, the message is good.
62  * Otherwise, the message is bad.
63  */
64  virtual bool validate_auth(call_message& msg) = 0;
65 
66  /**
67  * Validates a message received on the client from a server. This function
68  * must be reentrant. If the function returns true, the message is good.
69  * Otherwise, the message is bad.
70  */
71  virtual bool validate_auth(reply_message& msg) = 0;
72 };
73 
74 } // cppipc
75 
76 #endif
virtual bool validate_auth(call_message &msg)=0
virtual void apply_auth(call_message &msg)=0