Skip to content

Commit

Permalink
Remove a lot of pointless 'struct' keywords.
Browse files Browse the repository at this point in the history
This is the commit that f3295e0 _should_ have been. Yesterday I just
added some typedefs so that I didn't have to wear out my fingers
typing 'struct' in new code, but what I ought to have done is to move
all the typedefs into defs.h with the rest, and then go through
cleaning up the legacy 'struct's all through the existing code.

But I was mostly trying to concentrate on getting the test suite
finished, so I just did the minimum. Now it's time to come back and do
it better.
  • Loading branch information
sgtatham committed Jan 4, 2019
1 parent abebfdf commit 3569004
Show file tree
Hide file tree
Showing 39 changed files with 452 additions and 449 deletions.
16 changes: 8 additions & 8 deletions cmdgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ int main(int argc, char **argv)
bool errs = false, nogo = false;
int intype = SSH_KEYTYPE_UNOPENABLE;
int sshver = 0;
struct ssh2_userkey *ssh2key = NULL;
struct RSAKey *ssh1key = NULL;
ssh2_userkey *ssh2key = NULL;
RSAKey *ssh1key = NULL;
strbuf *ssh2blob = NULL;
char *ssh2alg = NULL;
char *old_passphrase = NULL, *new_passphrase = NULL;
Expand Down Expand Up @@ -696,29 +696,29 @@ int main(int argc, char **argv)
if (keytype == DSA) {
struct dss_key *dsskey = snew(struct dss_key);
dsa_generate(dsskey, bits, progressfn, &prog);
ssh2key = snew(struct ssh2_userkey);
ssh2key = snew(ssh2_userkey);
ssh2key->key = &dsskey->sshk;
ssh1key = NULL;
} else if (keytype == ECDSA) {
struct ecdsa_key *ek = snew(struct ecdsa_key);
ecdsa_generate(ek, bits, progressfn, &prog);
ssh2key = snew(struct ssh2_userkey);
ssh2key = snew(ssh2_userkey);
ssh2key->key = &ek->sshk;
ssh1key = NULL;
} else if (keytype == ED25519) {
struct eddsa_key *ek = snew(struct eddsa_key);
eddsa_generate(ek, bits, progressfn, &prog);
ssh2key = snew(struct ssh2_userkey);
ssh2key = snew(ssh2_userkey);
ssh2key->key = &ek->sshk;
ssh1key = NULL;
} else {
struct RSAKey *rsakey = snew(struct RSAKey);
RSAKey *rsakey = snew(RSAKey);
rsa_generate(rsakey, bits, progressfn, &prog);
rsakey->comment = NULL;
if (keytype == RSA1) {
ssh1key = rsakey;
} else {
ssh2key = snew(struct ssh2_userkey);
ssh2key = snew(ssh2_userkey);
ssh2key->key = &rsakey->sshk;
}
}
Expand Down Expand Up @@ -775,7 +775,7 @@ int main(int argc, char **argv)

case SSH_KEYTYPE_SSH1:
case SSH_KEYTYPE_SSH1_PUBLIC:
ssh1key = snew(struct RSAKey);
ssh1key = snew(RSAKey);
if (!load_encrypted) {
strbuf *blob;
BinarySource src[1];
Expand Down
22 changes: 21 additions & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct bufchain_tag bufchain;

typedef struct strbuf strbuf;

struct RSAKey;
typedef struct RSAKey RSAKey;

typedef struct BinarySink BinarySink;
typedef struct BinarySource BinarySource;
Expand Down Expand Up @@ -90,6 +90,26 @@ typedef struct PortFwdManager PortFwdManager;
typedef struct PortFwdRecord PortFwdRecord;
typedef struct ConnectionLayer ConnectionLayer;

typedef struct ssh_hashalg ssh_hashalg;
typedef struct ssh_hash ssh_hash;
typedef struct ssh_kex ssh_kex;
typedef struct ssh_kexes ssh_kexes;
typedef struct ssh_keyalg ssh_keyalg;
typedef struct ssh_key ssh_key;
typedef struct ssh_compressor ssh_compressor;
typedef struct ssh_decompressor ssh_decompressor;
typedef struct ssh_compression_alg ssh_compression_alg;
typedef struct ssh2_userkey ssh2_userkey;
typedef struct ssh2_macalg ssh2_macalg;
typedef struct ssh2_mac ssh2_mac;
typedef struct ssh2_cipheralg ssh2_cipheralg;
typedef struct ssh2_cipher ssh2_cipher;
typedef struct ssh2_ciphers ssh2_ciphers;
typedef struct ssh1_cipheralg ssh1_cipheralg;
typedef struct ssh1_cipher ssh1_cipher;
typedef struct dh_ctx dh_ctx;
typedef struct ecdh_key ecdh_key;

typedef struct dlgparam dlgparam;

typedef struct settings_w settings_w;
Expand Down
54 changes: 27 additions & 27 deletions import.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@

static bool openssh_pem_encrypted(const Filename *file);
static bool openssh_new_encrypted(const Filename *file);
static struct ssh2_userkey *openssh_pem_read(
static ssh2_userkey *openssh_pem_read(
const Filename *file, const char *passphrase, const char **errmsg_p);
static struct ssh2_userkey *openssh_new_read(
static ssh2_userkey *openssh_new_read(
const Filename *file, const char *passphrase, const char **errmsg_p);
static bool openssh_auto_write(
const Filename *file, struct ssh2_userkey *key, const char *passphrase);
const Filename *file, ssh2_userkey *key, const char *passphrase);
static bool openssh_pem_write(
const Filename *file, struct ssh2_userkey *key, const char *passphrase);
const Filename *file, ssh2_userkey *key, const char *passphrase);
static bool openssh_new_write(
const Filename *file, struct ssh2_userkey *key, const char *passphrase);
const Filename *file, ssh2_userkey *key, const char *passphrase);

static bool sshcom_encrypted(const Filename *file, char **comment);
static struct ssh2_userkey *sshcom_read(
static ssh2_userkey *sshcom_read(
const Filename *file, const char *passphrase, const char **errmsg_p);
static bool sshcom_write(
const Filename *file, struct ssh2_userkey *key, const char *passphrase);
const Filename *file, ssh2_userkey *key, const char *passphrase);

/*
* Given a key type, determine whether we know how to import it.
Expand Down Expand Up @@ -83,15 +83,15 @@ bool import_encrypted(const Filename *filename, int type, char **comment)
* Import an SSH-1 key.
*/
int import_ssh1(const Filename *filename, int type,
struct RSAKey *key, char *passphrase, const char **errmsg_p)
RSAKey *key, char *passphrase, const char **errmsg_p)
{
return 0;
}

/*
* Import an SSH-2 key.
*/
struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
ssh2_userkey *import_ssh2(const Filename *filename, int type,
char *passphrase, const char **errmsg_p)
{
if (type == SSH_KEYTYPE_OPENSSH_PEM)
Expand All @@ -106,7 +106,7 @@ struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
/*
* Export an SSH-1 key.
*/
bool export_ssh1(const Filename *filename, int type, struct RSAKey *key,
bool export_ssh1(const Filename *filename, int type, RSAKey *key,
char *passphrase)
{
return false;
Expand All @@ -116,7 +116,7 @@ bool export_ssh1(const Filename *filename, int type, struct RSAKey *key,
* Export an SSH-2 key.
*/
bool export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase)
ssh2_userkey *key, char *passphrase)
{
if (type == SSH_KEYTYPE_OPENSSH_AUTO)
return openssh_auto_write(filename, key, passphrase);
Expand Down Expand Up @@ -495,15 +495,15 @@ static bool openssh_pem_encrypted(const Filename *filename)
return ret;
}

static struct ssh2_userkey *openssh_pem_read(
static ssh2_userkey *openssh_pem_read(
const Filename *filename, const char *passphrase, const char **errmsg_p)
{
struct openssh_pem_key *key = load_openssh_pem_key(filename, errmsg_p);
struct ssh2_userkey *retkey;
ssh2_userkey *retkey;
const ssh_keyalg *alg;
BinarySource src[1];
int i, num_integers;
struct ssh2_userkey *retval = NULL;
ssh2_userkey *retval = NULL;
const char *errmsg;
strbuf *blob = strbuf_new();
int privptr = 0, publen;
Expand Down Expand Up @@ -659,7 +659,7 @@ static struct ssh2_userkey *openssh_pem_read(
pubkey.data.len -= 1;

/* Construct the key */
retkey = snew(struct ssh2_userkey);
retkey = snew(ssh2_userkey);

put_stringz(blob, alg->ssh_id);
put_stringz(blob, curve->name);
Expand Down Expand Up @@ -737,7 +737,7 @@ static struct ssh2_userkey *openssh_pem_read(
* the sanity checks for free.
*/
assert(privptr > 0); /* should have bombed by now if not */
retkey = snew(struct ssh2_userkey);
retkey = snew(ssh2_userkey);
alg = (key->keytype == OP_RSA ? &ssh_rsa : &ssh_dss);
retkey->key = ssh_key_new_priv(
alg, make_ptrlen(blob->u, privptr),
Expand Down Expand Up @@ -774,7 +774,7 @@ static struct ssh2_userkey *openssh_pem_read(
}

static bool openssh_pem_write(
const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
const Filename *filename, ssh2_userkey *key, const char *passphrase)
{
strbuf *pubblob, *privblob, *outblob;
unsigned char *spareblob;
Expand Down Expand Up @@ -1331,12 +1331,12 @@ static bool openssh_new_encrypted(const Filename *filename)
return ret;
}

static struct ssh2_userkey *openssh_new_read(
static ssh2_userkey *openssh_new_read(
const Filename *filename, const char *passphrase, const char **errmsg_p)
{
struct openssh_new_key *key = load_openssh_new_key(filename, errmsg_p);
struct ssh2_userkey *retkey = NULL;
struct ssh2_userkey *retval = NULL;
ssh2_userkey *retkey = NULL;
ssh2_userkey *retval = NULL;
const char *errmsg;
unsigned checkint;
BinarySource src[1];
Expand Down Expand Up @@ -1423,7 +1423,7 @@ static struct ssh2_userkey *openssh_new_read(
goto error;
}

retkey = snew(struct ssh2_userkey);
retkey = snew(ssh2_userkey);
retkey->key = NULL;
retkey->comment = NULL;

Expand Down Expand Up @@ -1512,7 +1512,7 @@ static struct ssh2_userkey *openssh_new_read(
}

static bool openssh_new_write(
const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
const Filename *filename, ssh2_userkey *key, const char *passphrase)
{
strbuf *pubblob, *privblob, *cblob;
int padvalue, i;
Expand Down Expand Up @@ -1641,7 +1641,7 @@ static bool openssh_new_write(
* concrete OpenSSH output formats based on the key type.
*/
static bool openssh_auto_write(
const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
const Filename *filename, ssh2_userkey *key, const char *passphrase)
{
/*
* The old OpenSSH format supports a fixed list of key types. We
Expand Down Expand Up @@ -1966,7 +1966,7 @@ static ptrlen BinarySource_get_mp_sshcom_as_string(BinarySource *src)
#define get_mp_sshcom_as_string(bs) \
BinarySource_get_mp_sshcom_as_string(BinarySource_UPCAST(bs))

static struct ssh2_userkey *sshcom_read(
static ssh2_userkey *sshcom_read(
const Filename *filename, const char *passphrase, const char **errmsg_p)
{
struct sshcom_key *key = load_sshcom_key(filename, errmsg_p);
Expand All @@ -1978,7 +1978,7 @@ static struct ssh2_userkey *sshcom_read(
const char prefix_dsa[] = "dl-modp{sign{dsa";
enum { RSA, DSA } type;
bool encrypted;
struct ssh2_userkey *ret = NULL, *retkey;
ssh2_userkey *ret = NULL, *retkey;
const ssh_keyalg *alg;
strbuf *blob = NULL;

Expand Down Expand Up @@ -2151,7 +2151,7 @@ static struct ssh2_userkey *sshcom_read(
put_mp_ssh2_from_string(blob, x.ptr, x.len);
}

retkey = snew(struct ssh2_userkey);
retkey = snew(ssh2_userkey);
retkey->key = ssh_key_new_priv(
alg, make_ptrlen(blob->u, publen),
make_ptrlen(blob->u + publen, blob->len - publen));
Expand All @@ -2178,7 +2178,7 @@ static struct ssh2_userkey *sshcom_read(
}

static bool sshcom_write(
const Filename *filename, struct ssh2_userkey *key, const char *passphrase)
const Filename *filename, ssh2_userkey *key, const char *passphrase)
{
strbuf *pubblob, *privblob, *outblob;
ptrlen numbers[6];
Expand Down
Loading

0 comments on commit 3569004

Please sign in to comment.