8c812766fe58c19238758bdc8851fc24a828ed37
[folly.git] / folly / io / async / ssl / SSLErrors.h
1 /*
2  * Copyright 2017 Facebook, Inc.
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  *   http://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 #pragma once
17
18 #include <folly/Optional.h>
19 #include <folly/io/async/AsyncSocketException.h>
20
21 namespace folly {
22
23 enum class SSLError {
24   CLIENT_RENEGOTIATION, // A client tried to renegotiate with this server
25   INVALID_RENEGOTIATION, // We attempted to start a renegotiation.
26   EARLY_WRITE, // Wrote before SSL connection established.
27   SSL_ERROR, // An error related to SSL
28   NETWORK_ERROR, // An error related to the network.
29   EOF_ERROR, // The peer terminated the connection correctly.
30 };
31
32 class SSLException : public folly::AsyncSocketException {
33  public:
34   SSLException(
35       int sslError,
36       unsigned long errError,
37       int sslOperationReturnValue,
38       int errno_copy);
39
40   explicit SSLException(SSLError error);
41
42   SSLError getSSLError() const {
43     return sslError;
44   }
45
46  private:
47   SSLError sslError;
48 };
49 }