Implement queue with O(1) operations, and correct some math.
[tor/rransom.git] / src / common / tortls.h
blob44e3b499ef117c990eb39092434568812da7be73
1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2009, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #ifndef _TOR_TORTLS_H
7 #define _TOR_TORTLS_H
9 /**
10 * \file tortls.h
11 * \brief Headers for tortls.c
12 **/
14 #include "crypto.h"
15 #include "compat.h"
17 /* Opaque structure to hold a TLS connection. */
18 typedef struct tor_tls_t tor_tls_t;
20 /* Possible return values for most tor_tls_* functions. */
21 #define _MIN_TOR_TLS_ERROR_VAL -9
22 #define TOR_TLS_ERROR_MISC -9
23 /* Rename to unexpected close or something. XXXX */
24 #define TOR_TLS_ERROR_IO -8
25 #define TOR_TLS_ERROR_CONNREFUSED -7
26 #define TOR_TLS_ERROR_CONNRESET -6
27 #define TOR_TLS_ERROR_NO_ROUTE -5
28 #define TOR_TLS_ERROR_TIMEOUT -4
29 #define TOR_TLS_CLOSE -3
30 #define TOR_TLS_WANTREAD -2
31 #define TOR_TLS_WANTWRITE -1
32 #define TOR_TLS_DONE 0
34 /** Collection of case statements for all TLS errors that are not due to
35 * underlying IO failure. */
36 #define CASE_TOR_TLS_ERROR_ANY_NONIO \
37 case TOR_TLS_ERROR_MISC: \
38 case TOR_TLS_ERROR_CONNREFUSED: \
39 case TOR_TLS_ERROR_CONNRESET: \
40 case TOR_TLS_ERROR_NO_ROUTE: \
41 case TOR_TLS_ERROR_TIMEOUT
43 /** Use this macro in a switch statement to catch _any_ TLS error. That way,
44 * if more errors are added, your switches will still work. */
45 #define CASE_TOR_TLS_ERROR_ANY \
46 CASE_TOR_TLS_ERROR_ANY_NONIO: \
47 case TOR_TLS_ERROR_IO
49 #define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE)
50 const char *tor_tls_err_to_string(int err);
52 void tor_tls_free_all(void);
53 int tor_tls_context_new(crypto_pk_env_t *rsa, unsigned int key_lifetime);
54 tor_tls_t *tor_tls_new(int sock, int is_server);
55 void tor_tls_set_logged_address(tor_tls_t *tls, const char *address);
56 void tor_tls_set_renegotiate_callback(tor_tls_t *tls,
57 void (*cb)(tor_tls_t *, void *arg),
58 void *arg);
59 int tor_tls_is_server(tor_tls_t *tls);
60 void tor_tls_free(tor_tls_t *tls);
61 int tor_tls_peer_has_cert(tor_tls_t *tls);
62 int tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity);
63 int tor_tls_check_lifetime(tor_tls_t *tls, int tolerance);
64 int tor_tls_read(tor_tls_t *tls, char *cp, size_t len);
65 int tor_tls_write(tor_tls_t *tls, const char *cp, size_t n);
66 int tor_tls_handshake(tor_tls_t *tls);
67 int tor_tls_renegotiate(tor_tls_t *tls);
68 int tor_tls_shutdown(tor_tls_t *tls);
69 int tor_tls_get_pending_bytes(tor_tls_t *tls);
70 size_t tor_tls_get_forced_write_size(tor_tls_t *tls);
72 void tor_tls_get_n_raw_bytes(tor_tls_t *tls,
73 size_t *n_read, size_t *n_written);
75 void tor_tls_get_buffer_sizes(tor_tls_t *tls,
76 int *rbuf_capacity, int *rbuf_bytes,
77 int *wbuf_capacity, int *wbuf_bytes);
79 int tor_tls_used_v1_handshake(tor_tls_t *tls);
81 /* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
83 #define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
85 void _check_no_tls_errors(const char *fname, int line);
87 #endif