cert: move cert enums & struct to its own header
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
diff --git a/include/git2.h b/include/git2.h
index 82ac1d3..7f49f8f 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -15,6 +15,7 @@
#include "git2/blame.h"
#include "git2/branch.h"
#include "git2/buffer.h"
+#include "git2/cert.h"
#include "git2/checkout.h"
#include "git2/cherrypick.h"
#include "git2/clone.h"
diff --git a/include/git2/cert.h b/include/git2/cert.h
new file mode 100644
index 0000000..61a92d4
--- /dev/null
+++ b/include/git2/cert.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_git_cert_h__
+#define INCLUDE_git_cert_h__
+
+#include "common.h"
+
+/**
+ * @file git2/cert.h
+ * @brief Git certificate objects
+ * @defgroup git_cert Certificate objects
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Type of host certificate structure that is passed to the check callback
+ */
+typedef enum git_cert_t {
+ /**
+ * No information about the certificate is available. This may
+ * happen when using curl.
+ */
+ GIT_CERT_NONE,
+ /**
+ * The `data` argument to the callback will be a pointer to
+ * the DER-encoded data.
+ */
+ GIT_CERT_X509,
+ /**
+ * The `data` argument to the callback will be a pointer to a
+ * `git_cert_hostkey` structure.
+ */
+ GIT_CERT_HOSTKEY_LIBSSH2,
+ /**
+ * The `data` argument to the callback will be a pointer to a
+ * `git_strarray` with `name:content` strings containing
+ * information about the certificate. This is used when using
+ * curl.
+ */
+ GIT_CERT_STRARRAY,
+} git_cert_t;
+
+/**
+ * Parent type for `git_cert_hostkey` and `git_cert_x509`.
+ */
+struct git_cert {
+ /**
+ * Type of certificate. A `GIT_CERT_` value.
+ */
+ git_cert_t cert_type;
+};
+
+/**
+ * Callback for the user's custom certificate checks.
+ *
+ * @param cert The host certificate
+ * @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
+ * this certificate is valid
+ * @param host Hostname of the host libgit2 connected to
+ * @param payload Payload provided by the caller
+ * @return 0 to proceed with the connection, < 0 to fail the connection
+ * or > 0 to indicate that the callback refused to act and that
+ * the existing validity determination should be honored
+ */
+typedef int GIT_CALLBACK(git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
+
+/**
+ * Type of SSH host fingerprint
+ */
+typedef enum {
+ /** MD5 is available */
+ GIT_CERT_SSH_MD5 = (1 << 0),
+ /** SHA-1 is available */
+ GIT_CERT_SSH_SHA1 = (1 << 1),
+} git_cert_ssh_t;
+
+/**
+ * Hostkey information taken from libssh2
+ */
+typedef struct {
+ git_cert parent; /**< The parent cert */
+
+ /**
+ * 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.
+ */
+ 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];
+} git_cert_hostkey;
+
+/**
+ * X.509 certificate information
+ */
+typedef struct {
+ git_cert parent; /**< The parent cert */
+
+ /**
+ * Pointer to the X.509 certificate data
+ */
+ void *data;
+
+ /**
+ * Length of the memory block pointed to by `data`.
+ */
+ size_t len;
+} git_cert_x509;
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/include/git2/proxy.h b/include/git2/proxy.h
index 0b3b1fa..f959ae2 100644
--- a/include/git2/proxy.h
+++ b/include/git2/proxy.h
@@ -8,6 +8,8 @@
#define INCLUDE_git_proxy_h__
#include "common.h"
+
+#include "cert.h"
#include "cred.h"
GIT_BEGIN_DECL
@@ -67,7 +69,7 @@ typedef struct {
* connection to proceed. Returns 0 to allow the connection
* or a negative value to indicate an error.
*/
- git_transport_certificate_check_cb certificate_check;
+ git_transport_certificate_check_cb certificate_check;
/**
* Payload to be provided to the credentials and certificate
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 5b42634..5122bc8 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -10,6 +10,7 @@
#include "indexer.h"
#include "net.h"
#include "types.h"
+#include "cert.h"
#include "cred.h"
/**
@@ -24,58 +25,6 @@ GIT_BEGIN_DECL
/** Signature of a function which creates a transport */
typedef int GIT_CALLBACK(git_transport_cb)(git_transport **out, git_remote *owner, void *param);
-/**
- * Type of SSH host fingerprint
- */
-typedef enum {
- /** MD5 is available */
- GIT_CERT_SSH_MD5 = (1 << 0),
- /** SHA-1 is available */
- GIT_CERT_SSH_SHA1 = (1 << 1),
-} git_cert_ssh_t;
-
-/**
- * Hostkey information taken from libssh2
- */
-typedef struct {
- git_cert parent; /**< The parent cert */
-
- /**
- * 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.
- */
- 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];
-} git_cert_hostkey;
-
-/**
- * X.509 certificate information
- */
-typedef struct {
- git_cert parent; /**< The parent cert */
-
- /**
- * Pointer to the X.509 certificate data
- */
- void *data;
-
- /**
- * Length of the memory block pointed to by `data`.
- */
- size_t len;
-} git_cert_x509;
-
/** @} */
GIT_END_DECL
diff --git a/include/git2/types.h b/include/git2/types.h
index 9b384ca..dab46ea 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -256,56 +256,9 @@ typedef int GIT_CALLBACK(git_transport_message_cb)(const char *str, int len, voi
/**
- * Type of host certificate structure that is passed to the check callback
- */
-typedef enum git_cert_t {
- /**
- * No information about the certificate is available. This may
- * happen when using curl.
- */
- GIT_CERT_NONE,
- /**
- * The `data` argument to the callback will be a pointer to
- * the DER-encoded data.
- */
- GIT_CERT_X509,
- /**
- * The `data` argument to the callback will be a pointer to a
- * `git_cert_hostkey` structure.
- */
- GIT_CERT_HOSTKEY_LIBSSH2,
- /**
- * The `data` argument to the callback will be a pointer to a
- * `git_strarray` with `name:content` strings containing
- * information about the certificate. This is used when using
- * curl.
- */
- GIT_CERT_STRARRAY,
-} git_cert_t;
-
-/**
* Parent type for `git_cert_hostkey` and `git_cert_x509`.
*/
-typedef struct {
- /**
- * Type of certificate. A `GIT_CERT_` value.
- */
- git_cert_t cert_type;
-} git_cert;
-
-/**
- * Callback for the user's custom certificate checks.
- *
- * @param cert The host certificate
- * @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
- * this certificate is valid
- * @param host Hostname of the host libgit2 connected to
- * @param payload Payload provided by the caller
- * @return 0 to proceed with the connection, < 0 to fail the connection
- * or > 0 to indicate that the callback refused to act and that
- * the existing validity determination should be honored
- */
-typedef int GIT_CALLBACK(git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
+typedef struct git_cert git_cert;
/**
* Opaque structure representing a submodule.