Skip to content

Commit 80792a5

Browse files
committed
types: Move structs from specific module to types
Those structs were originally defined in specific modules (e.g. rsa) and globally aliased to a public name in types (formerly ossl_typ). Since the modules also depended on the public types, there was a circular dependency: types import the struct to alias it, and the module containing the struct imports types to use the alias. The amount of circular dependency ended up confusing the frontend, and now some new additions might fail (especially if in a `version` / `static if`). Since those structs have all been deprecated, and the public name is opaque, they are not needed after OpenSSL 1.1.0 anyway. And since the `types` module is publicly imported everywhere, moving the struct definition will simplify the dependency tree, at the expense of making the struct definition most widely available.
1 parent 70354fb commit 80792a5

File tree

6 files changed

+220
-207
lines changed

6 files changed

+220
-207
lines changed

source/deimos/openssl/bn.d

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -310,66 +310,6 @@ void BN_with_flags()(BIGNUM* dest, BIGNUM* b, int n) {
310310
| n;
311311
}
312312

313-
/* Already declared in types.h */
314-
version (none) {
315-
alias bignum_st BIGNUM;
316-
/* Used for temp variables (declaration hidden in bn_lcl.h) */
317-
alias bignum_ctx BN_CTX;
318-
alias bn_blinding_st BN_BLINDING;
319-
alias bn_mont_ctx_st BN_MONT_CTX;
320-
alias bn_recp_ctx_st BN_RECP_CTX;
321-
alias bn_gencb_st BN_GENCB;
322-
}
323-
324-
struct bignum_st
325-
{
326-
BN_ULONG* d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
327-
int top; /* Index of last used d +1. */
328-
/* The next are internal book keeping for bn_expand. */
329-
int dmax; /* Size of the d array. */
330-
int neg; /* one if the number is negative */
331-
int flags;
332-
};
333-
334-
/* Used for montgomery multiplication */
335-
struct bn_mont_ctx_st
336-
{
337-
int ri; /* number of bits in R */
338-
BIGNUM RR; /* used to convert to montgomery form */
339-
BIGNUM N; /* The modulus */
340-
BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
341-
* (Ni is only stored for bignum algorithm) */
342-
BN_ULONG[2] n0;/* least significant word(s) of Ni;
343-
(type changed with 0.9.9, was "BN_ULONG n0;" before) */
344-
int flags;
345-
};
346-
347-
/* Used for reciprocal division/mod functions
348-
* It cannot be shared between threads
349-
*/
350-
struct bn_recp_ctx_st
351-
{
352-
BIGNUM N; /* the divisor */
353-
BIGNUM Nr; /* the reciprocal */
354-
int num_bits;
355-
int shift;
356-
int flags;
357-
};
358-
359-
/* Used for slow "generation" functions. */
360-
struct bn_gencb_st
361-
{
362-
uint ver; /* To handle binary (in)compatibility */
363-
void* arg; /* callback-specific data */
364-
union cb_
365-
{
366-
/* if(ver==1) - handles old style callbacks */
367-
ExternC!(void function(int, int, void*)) cb_1;
368-
/* if(ver==2) - new callback style */
369-
ExternC!(int function(int, int, BN_GENCB*)) cb_2;
370-
}
371-
cb_ cb;
372-
};
373313
/* Wrapper function to make using BN_GENCB easier, */
374314
int BN_GENCB_call(BN_GENCB* cb, int a, int b);
375315
/* Macro to populate a BN_GENCB structure with an "old"-style callback */

source/deimos/openssl/buffer.d

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,8 @@ nothrow:
6767

6868
import core.stdc.config;
6969

70-
//#if !defined(NO_SYS_TYPES_H)
71-
//#include <sys/types.h>
72-
//#endif
73-
74-
/* Already declared in types.h */
75-
/* typedef buf_mem_st BUF_MEM; */
76-
77-
struct buf_mem_st
78-
{
79-
size_t length; /* current number of bytes */
80-
char* data;
81-
size_t max; /* size of buffer */
82-
};
70+
// Without this, the frontend is unaware of types defined in `static if`.
71+
private enum avoidDMDIssue16666 = __traits(allMembers, deimos.openssl.types);
8372

8473
BUF_MEM* BUF_MEM_new();
8574
void BUF_MEM_free(BUF_MEM* a);

source/deimos/openssl/evp.d

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -76,67 +76,11 @@ alias EVP_PKEY_CMAC = NID_cmac;
7676
extern (C):
7777
nothrow:
7878

79-
/* Type needs to be a bit field
80-
* Sub-type needs to be for variations on the method, as in_, can it do
81-
* arbitrary encryption.... */
82-
struct evp_pkey_st
83-
{
84-
int type;
85-
int save_type;
86-
int references;
87-
const(EVP_PKEY_ASN1_METHOD)* ameth;
88-
ENGINE* engine;
89-
union pkey_ {
90-
char* ptr;
91-
version(OPENSSL_NO_RSA) {} else {
92-
RSA* rsa; /* RSA */
93-
}
94-
version(OPENSSL_NO_DSA) {} else {
95-
dsa_st* dsa; /* DSA */
96-
}
97-
version(OPENSSL_NO_DH) {} else {
98-
dh_st* dh; /* DH */
99-
}
100-
version(OPENSSL_NO_EC) {} else {
101-
ec_key_st* ec; /* ECC */
102-
}
103-
}
104-
pkey_ pkey;
105-
int save_parameters;
106-
STACK_OF!(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
107-
} /* EVP_PKEY */;
108-
10979
enum EVP_PKEY_MO_SIGN = 0x0001;
11080
enum EVP_PKEY_MO_VERIFY = 0x0002;
11181
enum EVP_PKEY_MO_ENCRYPT = 0x0004;
11282
enum EVP_PKEY_MO_DECRYPT = 0x0008;
11383

114-
// #ifndef EVP_MD
115-
struct env_md_st
116-
{
117-
int type;
118-
int pkey_type;
119-
int md_size;
120-
c_ulong flags;
121-
ExternC!(int function(EVP_MD_CTX* ctx)) init_;
122-
ExternC!(int function(EVP_MD_CTX* ctx,const(void)* data,size_t count)) update;
123-
ExternC!(int function(EVP_MD_CTX* ctx,ubyte* md)) final_;
124-
ExternC!(int function(EVP_MD_CTX* to,const(EVP_MD_CTX)* from)) copy;
125-
ExternC!(int function(EVP_MD_CTX* ctx)) cleanup;
126-
127-
/* FIXME: prototype these some day */
128-
ExternC!(int function(int type, const(ubyte)* m, uint m_length,
129-
ubyte* sigret, uint* siglen, void* key)) sign;
130-
ExternC!(int function(int type, const(ubyte)* m, uint m_length,
131-
const(ubyte)* sigbuf, uint siglen,
132-
void* key)) verify;
133-
int[5] required_pkey_type; /*EVP_PKEY_xxx */
134-
int block_size;
135-
int ctx_size; /* how big does the ctx->md_data need to be */
136-
/* control function */
137-
ExternC!(int function(EVP_MD_CTX* ctx, int cmd, int p1, void* p2)) md_ctrl;
138-
} /* EVP_MD */;
139-
14084
alias evp_sign_method = typeof(*(ExternC!(int function(int type,const(ubyte)* m,
14185
uint m_length,ubyte* sigret,
14286
uint* siglen, void* key))).init);
@@ -214,18 +158,6 @@ version (OPENSSL_NO_RSA) {
214158

215159
// #endif /* !EVP_MD */
216160

217-
struct env_md_ctx_st
218-
{
219-
const(EVP_MD)* digest;
220-
ENGINE* engine; /* functional reference if 'digest' is ENGINE-provided */
221-
c_ulong flags;
222-
void* md_data;
223-
/* Public key context for sign/verify */
224-
EVP_PKEY_CTX* pctx;
225-
/* Update function: usually copied from EVP_MD */
226-
ExternC!(int function(EVP_MD_CTX* ctx,const(void)* data,size_t count)) update;
227-
} /* EVP_MD_CTX */;
228-
229161
/* values for EVP_MD_CTX flags */
230162

231163
enum EVP_MD_CTX_FLAG_ONESHOT = 0x0001; /* digest update will be called
@@ -252,25 +184,6 @@ enum EVP_MD_CTX_FLAG_PAD_PSS = 0x20; /* PSS mode */
252184

253185
enum EVP_MD_CTX_FLAG_NO_INIT = 0x0100; /* Don't initialize md_data */
254186

255-
struct evp_cipher_st
256-
{
257-
int nid;
258-
int block_size;
259-
int key_len; /* Default value for variable length ciphers */
260-
int iv_len;
261-
c_ulong flags; /* Various flags */
262-
ExternC!(int function(EVP_CIPHER_CTX* ctx, const(ubyte)* key,
263-
const(ubyte)* iv, int enc)) init_; /* init key */
264-
ExternC!(int function(EVP_CIPHER_CTX* ctx, ubyte* out_,
265-
const(ubyte)* in_, size_t inl)) do_cipher;/* encrypt/decrypt data */
266-
ExternC!(int function(EVP_CIPHER_CTX*)) cleanup; /* cleanup ctx */
267-
int ctx_size; /* how big ctx->cipher_data needs to be */
268-
ExternC!(int function(EVP_CIPHER_CTX*, ASN1_TYPE*)) set_asn1_parameters; /* Populate a ASN1_TYPE with parameters */
269-
ExternC!(int function(EVP_CIPHER_CTX*, ASN1_TYPE*)) get_asn1_parameters; /* Get parameters from a ASN1_TYPE */
270-
ExternC!(int function(EVP_CIPHER_CTX*, int type, int arg, void* ptr)) ctrl; /* Miscellaneous operations */
271-
void* app_data; /* Application data */
272-
} /* EVP_CIPHER */;
273-
274187
/* Values for cipher flags */
275188

276189
/* Modes for ciphers */

source/deimos/openssl/hmac.d

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ enum HMAC_MAX_MD_CBLOCK = 128; /* largest known is SHA512 */
7272
extern (C):
7373
nothrow:
7474

75-
struct hmac_ctx_st {
76-
const(EVP_MD)* md;
77-
EVP_MD_CTX md_ctx;
78-
EVP_MD_CTX i_ctx;
79-
EVP_MD_CTX o_ctx;
80-
uint key_length;
81-
ubyte[HMAC_MAX_MD_CBLOCK] key;
75+
static if (OPENSSL_VERSION_BEFORE(1, 1, 0))
76+
{
77+
struct hmac_ctx_st {
78+
const(EVP_MD)* md;
79+
EVP_MD_CTX md_ctx;
80+
EVP_MD_CTX i_ctx;
81+
EVP_MD_CTX o_ctx;
82+
uint key_length;
83+
ubyte[HMAC_MAX_MD_CBLOCK] key;
8284
}
83-
alias hmac_ctx_st HMAC_CTX;
85+
86+
alias HMAC_CTX = hmac_ctx_st;
87+
}
88+
else
89+
struct HMAC_CTX;
8490

8591
auto HMAC_size()(HMAC_CTX* e) { return EVP_MD_size(e.md); }
8692

source/deimos/openssl/pem.d

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,19 @@ enum PEM_STRING_ECPRIVATEKEY = "EC PRIVATE KEY";
139139
enum PEM_STRING_PARAMETERS = "PARAMETERS";
140140
enum PEM_STRING_CMS = "CMS";
141141

142+
static if (OPENSSL_VERSION_BEFORE(1, 1, 0))
143+
{
142144
/* Note that this structure is initialised by PEM_SealInit and cleaned up
143-
by PEM_SealFinal (at least for now) */
144-
struct PEM_Encode_Seal_st {
145-
EVP_ENCODE_CTX encode;
146-
EVP_MD_CTX md;
147-
EVP_CIPHER_CTX cipher;
145+
by PEM_SealFinal (at least for now) */
146+
struct PEM_Encode_Seal_st {
147+
EVP_ENCODE_CTX encode;
148+
EVP_MD_CTX md;
149+
EVP_CIPHER_CTX cipher;
148150
}
149-
alias PEM_Encode_Seal_st PEM_ENCODE_SEAL_CTX;
151+
alias PEM_Encode_Seal_st PEM_ENCODE_SEAL_CTX;
152+
}
153+
else
154+
struct PEM_ENCODE_SEAL_CTX;
150155

151156
/* enc_type is one off */
152157
enum PEM_TYPE_ENCRYPTED = 10;

0 commit comments

Comments
 (0)