1# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import absolute_import, division, print_function
6
7INCLUDES = """
8#include <openssl/err.h>
9"""
10
11TYPES = """
12static const int Cryptography_HAS_EC_CODES;
13static const int Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR;
14static const int Cryptography_HAS_EVP_R_MEMORY_LIMIT_EXCEEDED;
15
16static const int ERR_LIB_DH;
17static const int ERR_LIB_EVP;
18static const int ERR_LIB_EC;
19static const int ERR_LIB_PEM;
20static const int ERR_LIB_ASN1;
21static const int ERR_LIB_RSA;
22static const int ERR_LIB_PKCS12;
23static const int ERR_LIB_SSL;
24static const int ERR_LIB_X509;
25
26static const int ERR_R_MALLOC_FAILURE;
27static const int EVP_R_MEMORY_LIMIT_EXCEEDED;
28
29static const int ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
30static const int ASN1_R_BUFFER_TOO_SMALL;
31static const int ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER;
32static const int ASN1_R_DATA_IS_WRONG;
33static const int ASN1_R_DECODE_ERROR;
34static const int ASN1_R_DEPTH_EXCEEDED;
35static const int ASN1_R_ENCODE_ERROR;
36static const int ASN1_R_ERROR_GETTING_TIME;
37static const int ASN1_R_ERROR_LOADING_SECTION;
38static const int ASN1_R_MSTRING_WRONG_TAG;
39static const int ASN1_R_NESTED_ASN1_STRING;
40static const int ASN1_R_NO_MATCHING_CHOICE_TYPE;
41static const int ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM;
42static const int ASN1_R_UNKNOWN_OBJECT_TYPE;
43static const int ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE;
44static const int ASN1_R_UNKNOWN_TAG;
45static const int ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE;
46static const int ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE;
47static const int ASN1_R_UNSUPPORTED_TYPE;
48static const int ASN1_R_WRONG_TAG;
49static const int ASN1_R_NO_CONTENT_TYPE;
50static const int ASN1_R_NO_MULTIPART_BODY_FAILURE;
51static const int ASN1_R_NO_MULTIPART_BOUNDARY;
52static const int ASN1_R_HEADER_TOO_LONG;
53
54static const int DH_R_INVALID_PUBKEY;
55
56static const int EVP_F_EVP_ENCRYPTFINAL_EX;
57
58static const int EVP_R_AES_KEY_SETUP_FAILED;
59static const int EVP_R_BAD_DECRYPT;
60static const int EVP_R_CIPHER_PARAMETER_ERROR;
61static const int EVP_R_CTRL_NOT_IMPLEMENTED;
62static const int EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED;
63static const int EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH;
64static const int EVP_R_DECODE_ERROR;
65static const int EVP_R_DIFFERENT_KEY_TYPES;
66static const int EVP_R_INITIALIZATION_ERROR;
67static const int EVP_R_INPUT_NOT_INITIALIZED;
68static const int EVP_R_INVALID_KEY_LENGTH;
69static const int EVP_R_KEYGEN_FAILURE;
70static const int EVP_R_MISSING_PARAMETERS;
71static const int EVP_R_NO_CIPHER_SET;
72static const int EVP_R_NO_DIGEST_SET;
73static const int EVP_R_PUBLIC_KEY_NOT_RSA;
74static const int EVP_R_UNKNOWN_PBE_ALGORITHM;
75static const int EVP_R_UNSUPPORTED_CIPHER;
76static const int EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION;
77static const int EVP_R_UNSUPPORTED_KEYLENGTH;
78static const int EVP_R_UNSUPPORTED_SALT_TYPE;
79static const int EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM;
80static const int EVP_R_WRONG_FINAL_BLOCK_LENGTH;
81static const int EVP_R_CAMELLIA_KEY_SETUP_FAILED;
82
83static const int EC_R_UNKNOWN_GROUP;
84
85static const int PEM_R_BAD_BASE64_DECODE;
86static const int PEM_R_BAD_DECRYPT;
87static const int PEM_R_BAD_END_LINE;
88static const int PEM_R_BAD_IV_CHARS;
89static const int PEM_R_BAD_PASSWORD_READ;
90static const int PEM_R_ERROR_CONVERTING_PRIVATE_KEY;
91static const int PEM_R_NO_START_LINE;
92static const int PEM_R_NOT_DEK_INFO;
93static const int PEM_R_NOT_ENCRYPTED;
94static const int PEM_R_NOT_PROC_TYPE;
95static const int PEM_R_PROBLEMS_GETTING_PASSWORD;
96static const int PEM_R_READ_KEY;
97static const int PEM_R_SHORT_HEADER;
98static const int PEM_R_UNSUPPORTED_CIPHER;
99static const int PEM_R_UNSUPPORTED_ENCRYPTION;
100
101static const int PKCS12_R_PKCS12_CIPHERFINAL_ERROR;
102
103static const int RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
104static const int RSA_R_DATA_TOO_LARGE_FOR_MODULUS;
105static const int RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY;
106static const int RSA_R_BLOCK_TYPE_IS_NOT_01;
107static const int RSA_R_BLOCK_TYPE_IS_NOT_02;
108static const int RSA_R_PKCS_DECODING_ERROR;
109static const int RSA_R_OAEP_DECODING_ERROR;
110
111static const int SSL_TLSEXT_ERR_OK;
112static const int SSL_TLSEXT_ERR_ALERT_WARNING;
113static const int SSL_TLSEXT_ERR_ALERT_FATAL;
114static const int SSL_TLSEXT_ERR_NOACK;
115
116static const int SSL_AD_CLOSE_NOTIFY;
117static const int SSL_AD_UNEXPECTED_MESSAGE;
118static const int SSL_AD_BAD_RECORD_MAC;
119static const int SSL_AD_RECORD_OVERFLOW;
120static const int SSL_AD_DECOMPRESSION_FAILURE;
121static const int SSL_AD_HANDSHAKE_FAILURE;
122static const int SSL_AD_BAD_CERTIFICATE;
123static const int SSL_AD_UNSUPPORTED_CERTIFICATE;
124static const int SSL_AD_CERTIFICATE_REVOKED;
125static const int SSL_AD_CERTIFICATE_EXPIRED;
126static const int SSL_AD_CERTIFICATE_UNKNOWN;
127static const int SSL_AD_ILLEGAL_PARAMETER;
128static const int SSL_AD_UNKNOWN_CA;
129static const int SSL_AD_ACCESS_DENIED;
130static const int SSL_AD_DECODE_ERROR;
131static const int SSL_AD_DECRYPT_ERROR;
132static const int SSL_AD_PROTOCOL_VERSION;
133static const int SSL_AD_INSUFFICIENT_SECURITY;
134static const int SSL_AD_INTERNAL_ERROR;
135static const int SSL_AD_USER_CANCELLED;
136static const int SSL_AD_NO_RENEGOTIATION;
137
138static const int SSL_AD_UNSUPPORTED_EXTENSION;
139static const int SSL_AD_CERTIFICATE_UNOBTAINABLE;
140static const int SSL_AD_UNRECOGNIZED_NAME;
141static const int SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE;
142static const int SSL_AD_BAD_CERTIFICATE_HASH_VALUE;
143static const int SSL_AD_UNKNOWN_PSK_IDENTITY;
144
145static const int X509_R_CERT_ALREADY_IN_HASH_TABLE;
146static const int X509_R_KEY_VALUES_MISMATCH;
147"""
148
149FUNCTIONS = """
150void ERR_error_string_n(unsigned long, char *, size_t);
151const char *ERR_lib_error_string(unsigned long);
152const char *ERR_func_error_string(unsigned long);
153const char *ERR_reason_error_string(unsigned long);
154unsigned long ERR_get_error(void);
155unsigned long ERR_peek_error(void);
156unsigned long ERR_peek_last_error(void);
157void ERR_clear_error(void);
158void ERR_put_error(int, int, int, const char *, int);
159
160int ERR_GET_LIB(unsigned long);
161int ERR_GET_FUNC(unsigned long);
162int ERR_GET_REASON(unsigned long);
163
164"""
165
166CUSTOMIZATIONS = """
167static const long Cryptography_HAS_EC_CODES = 1;
168
169#ifdef RSA_R_PKCS_DECODING_ERROR
170static const long Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR = 1;
171#else
172static const long Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR = 0;
173static const long RSA_R_PKCS_DECODING_ERROR = 0;
174#endif
175
176#ifdef EVP_R_MEMORY_LIMIT_EXCEEDED
177static const long Cryptography_HAS_EVP_R_MEMORY_LIMIT_EXCEEDED = 1;
178#else
179static const long EVP_R_MEMORY_LIMIT_EXCEEDED = 0;
180static const long Cryptography_HAS_EVP_R_MEMORY_LIMIT_EXCEEDED = 0;
181#endif
182"""
183