git_cert: child types use proper base type
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0aae4da..fa65991 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ v0.23 + 1
### API removals
+### Breaking API changes
+
+* `git_cert` descendent types now have a proper `parent` member
+
v0.23
------
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 2eeebd5..fd55eac 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -37,39 +37,32 @@ typedef enum {
* Hostkey information taken from libssh2
*/
typedef struct {
+ git_cert parent;
+
/**
- * Type of certificate. Here to share the header with
- * `git_cert`.
+ * A hostkey type from libssh2, either
+ * `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
*/
- git_cert_t cert_type;
- /**
- * A hostkey type from libssh2, either
- * `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
- */
git_cert_ssh_t type;
- /**
- * Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will
- * have the MD5 hash of the hostkey.
- */
+ /**
+ * Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will
+ * have the MD5 hash of the hostkey.
+ */
unsigned char hash_md5[16];
- /**
- * Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will
- * have the SHA-1 hash of the hostkey.
- */
- unsigned char hash_sha1[20];
+ /**
+ * Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will
+ * have the SHA-1 hash of the hostkey.
+ */
+ unsigned char hash_sha1[20];
} git_cert_hostkey;
/**
* X.509 certificate information
*/
typedef struct {
- /**
- * Type of certificate. Here to share the header with
- * `git_cert`.
- */
- git_cert_t cert_type;
+ git_cert parent;
/**
* Pointer to the X.509 certificate data
*/
diff --git a/src/curl_stream.c b/src/curl_stream.c
index 6534bdb..63421fc 100644
--- a/src/curl_stream.c
+++ b/src/curl_stream.c
@@ -67,9 +67,9 @@ static int curls_certificate(git_cert **out, git_stream *stream)
/* No information is available, can happen with SecureTransport */
if (certinfo->num_of_certs == 0) {
- s->cert_info.cert_type = GIT_CERT_NONE;
- s->cert_info.data = NULL;
- s->cert_info.len = 0;
+ s->cert_info.parent.cert_type = GIT_CERT_NONE;
+ s->cert_info.data = NULL;
+ s->cert_info.len = 0;
return 0;
}
@@ -85,11 +85,11 @@ static int curls_certificate(git_cert **out, git_stream *stream)
s->cert_info_strings.strings = (char **) strings.contents;
s->cert_info_strings.count = strings.length;
- s->cert_info.cert_type = GIT_CERT_STRARRAY;
- s->cert_info.data = &s->cert_info_strings;
- s->cert_info.len = strings.length;
+ s->cert_info.parent.cert_type = GIT_CERT_STRARRAY;
+ s->cert_info.data = &s->cert_info_strings;
+ s->cert_info.len = strings.length;
- *out = (git_cert *) &s->cert_info;
+ *out = &s->cert_info.parent;
return 0;
}
diff --git a/src/openssl_stream.c b/src/openssl_stream.c
index 958252e..1bd4f14 100644
--- a/src/openssl_stream.c
+++ b/src/openssl_stream.c
@@ -358,11 +358,12 @@ int openssl_certificate(git_cert **out, git_stream *stream)
return -1;
}
- st->cert_info.cert_type = GIT_CERT_X509;
+ st->cert_info.parent.cert_type = GIT_CERT_X509;
st->cert_info.data = encoded_cert;
st->cert_info.len = len;
- *out = (git_cert *)&st->cert_info;
+ *out = &st->cert_info.parent;
+
return 0;
}
diff --git a/src/stransport_stream.c b/src/stransport_stream.c
index 10e1916..33b6c5c 100644
--- a/src/stransport_stream.c
+++ b/src/stransport_stream.c
@@ -108,7 +108,7 @@ int stransport_certificate(git_cert **out, git_stream *stream)
return -1;
}
- st->cert_info.cert_type = GIT_CERT_X509;
+ st->cert_info.parent.cert_type = GIT_CERT_X509;
st->cert_info.data = (void *) CFDataGetBytePtr(st->der_data);
st->cert_info.len = CFDataGetLength(st->der_data);
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 83af137..0b0d4ba 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -525,10 +525,10 @@ static int _git_ssh_setup_conn(
goto done;
if (t->owner->certificate_check_cb != NULL) {
- git_cert_hostkey cert = { 0 }, *cert_ptr;
+ git_cert_hostkey cert = {{ 0 }}, *cert_ptr;
const char *key;
- cert.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
+ cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);
if (key != NULL) {
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index da047d6..0c43c4b 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -228,7 +228,7 @@ static int certificate_check(winhttp_stream *s, int valid)
}
giterr_clear();
- cert.cert_type = GIT_CERT_X509;
+ cert.parent.cert_type = GIT_CERT_X509;
cert.data = cert_ctx->pbCertEncoded;
cert.len = cert_ctx->cbCertEncoded;
error = t->owner->certificate_check_cb((git_cert *) &cert, valid, t->connection_data.host, t->owner->cred_acquire_payload);