Skip to content

Commit

Permalink
Add clang-format and apply it
Browse files Browse the repository at this point in the history
This patch contains no functional changes, it just enforces a new
coding standard. This clang-format was copied from libmodulemd.
  • Loading branch information
sgallagher committed Sep 20, 2017
1 parent 5985c09 commit 029db57
Show file tree
Hide file tree
Showing 18 changed files with 1,729 additions and 1,354 deletions.
60 changes: 60 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
# C format
Language: Cpp

BasedOnStyle: WebKit

AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: All
AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: GNU
BreakBeforeTernaryOperators: false
ColumnLimit: 79
CommentPragmas: '^ IWYU pragma:'
ContinuationIndentWidth: 2
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PointerAlignment: Right
ReflowComments: false
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

9 changes: 5 additions & 4 deletions include/authority.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#include "x509.h"

#ifndef _AUTHORITY_H
# define _AUTHORITY_H
#define _AUTHORITY_H

int
create_private_CA(TALLOC_CTX *mem_ctx, const struct sscg_options *options,
struct sscg_x509_cert **_cacert,
struct sscg_evp_pkey **_cakey);
create_private_CA (TALLOC_CTX *mem_ctx,
const struct sscg_options *options,
struct sscg_x509_cert **_cacert,
struct sscg_evp_pkey **_cakey);

#endif /* _AUTHORITY_H */
18 changes: 10 additions & 8 deletions include/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#ifndef _SSCG_BIGNUM_H
# define _SSCG_BIGNUM_H
#define _SSCG_BIGNUM_H

#include <openssl/bn.h>
#include "sscg.h"
Expand All @@ -27,24 +27,26 @@
/* Add definitions for some helper values added in OpenSSL 1.1.0
when building against OpenSSL 1.0.2 */
#ifndef BN_RAND_TOP_ANY
# define BN_RAND_TOP_ANY -1
#define BN_RAND_TOP_ANY -1
#endif

#ifndef BN_RAND_BOTTOM_ANY
# define BN_RAND_BOTTOM_ANY 0
#define BN_RAND_BOTTOM_ANY 0
#endif

struct sscg_bignum {
BIGNUM *bn;
struct sscg_bignum
{
BIGNUM *bn;
};


int
sscg_bignum_destructor(TALLOC_CTX *mem_ctx);
sscg_bignum_destructor (TALLOC_CTX *mem_ctx);

int
sscg_init_bignum(TALLOC_CTX *mem_ctx, unsigned long num,
struct sscg_bignum **bn);
sscg_init_bignum (TALLOC_CTX *mem_ctx,
unsigned long num,
struct sscg_bignum **bn);


#endif /* _SSCG_BIGNUM_H */
13 changes: 8 additions & 5 deletions include/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
#include "include/bignum.h"

#ifndef _SSCG_KEY_H
# define _SSCG_KEY_H
#define _SSCG_KEY_H

struct sscg_evp_pkey {
EVP_PKEY *evp_pkey;
struct sscg_evp_pkey
{
EVP_PKEY *evp_pkey;
};

int
sscg_generate_rsa_key(TALLOC_CTX *mem_ctx, int bits, struct sscg_bignum *e,
struct sscg_evp_pkey **_key);
sscg_generate_rsa_key (TALLOC_CTX *mem_ctx,
int bits,
struct sscg_bignum *e,
struct sscg_evp_pkey **_key);


#endif /* _SSCG_KEY_H */
14 changes: 7 additions & 7 deletions include/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include "key.h"

#ifndef _SERVICE_H
# define _SERVICE_H
#define _SERVICE_H

int
create_service_cert(TALLOC_CTX *mem_ctx,
const struct sscg_options *options,
struct sscg_x509_cert *ca_cert,
struct sscg_evp_pkey *ca_key,
struct sscg_x509_cert **_svc_cert,
struct sscg_evp_pkey **_svc_key);
create_service_cert (TALLOC_CTX *mem_ctx,
const struct sscg_options *options,
struct sscg_x509_cert *ca_cert,
struct sscg_evp_pkey *ca_key,
struct sscg_x509_cert **_svc_cert,
struct sscg_evp_pkey **_svc_key);

#endif /* _SERVICE_H */
156 changes: 87 additions & 69 deletions include/sscg.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,92 +28,110 @@
#include <stdint.h>

#ifndef _SSCG_H
# define _SSCG_H
#define _SSCG_H

/* TODO: implement internationalization */

#ifndef _
# ifdef HAVE_GETTEXT
# define _(STRING) gettext (STRING)
# else
# define _(STRING) STRING
# endif /* HAVE_GETTEXT */
#ifdef HAVE_GETTEXT
#define _(STRING) gettext (STRING)
#else
#define _(STRING) STRING
#endif /* HAVE_GETTEXT */
#endif /* _ */

#ifndef EOK
# define EOK 0
#define EOK 0
#endif

#ifndef discard_const
# define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
#define discard_const(ptr) ((void *)((uintptr_t) (ptr)))
#endif

#ifndef talloc_zfree
#define talloc_zfree(ptr) do { talloc_free(discard_const(ptr)); ptr = NULL; } while(0)
#define talloc_zfree(ptr) \
do \
{ \
talloc_free (discard_const (ptr)); \
ptr = NULL; \
} \
while (0)
#endif

#define CHECK_MEM(ptr) \
do { \
if (!ptr) { \
ret = ENOMEM; \
goto done; \
} \
} while(0)

#define CHECK_OK(_ret) \
do { \
if (_ret != EOK) { \
goto done; \
} \
} while(0)

#define CHECK_SSL(_sslret, _fn) \
do { \
if (_sslret != 1) { \
/* Get information about error from OpenSSL */ \
fprintf(stderr, "Error occurred in " #_fn ": [%s].\n", \
ERR_error_string(ERR_get_error(), NULL)); \
ret = EIO; \
goto done; \
} \
} while(0)

enum sscg_verbosity {
SSCG_QUIET = -1,
SSCG_DEFAULT,
SSCG_VERBOSE,
SSCG_DEBUG
#define CHECK_MEM(ptr) \
do \
{ \
if (!ptr) \
{ \
ret = ENOMEM; \
goto done; \
} \
} \
while (0)

#define CHECK_OK(_ret) \
do \
{ \
if (_ret != EOK) \
{ \
goto done; \
} \
} \
while (0)

#define CHECK_SSL(_sslret, _fn) \
do \
{ \
if (_sslret != 1) \
{ \
/* Get information about error from OpenSSL */ \
fprintf (stderr, \
"Error occurred in " #_fn ": [%s].\n", \
ERR_error_string (ERR_get_error (), NULL)); \
ret = EIO; \
goto done; \
} \
} \
while (0)

enum sscg_verbosity
{
SSCG_QUIET = -1,
SSCG_DEFAULT,
SSCG_VERBOSE,
SSCG_DEBUG
};

struct sscg_options {
/* How noisy to be when printing information */
enum sscg_verbosity verbosity;

/* Whether to print the version and exit */
bool print_version;

/* How long should certificates be valid (in days) */
int lifetime;

/* Subject information */
const char *country;
const char *state;
const char *locality;
const char *org;
const char *org_unit;
const char *email;
const char *hostname;
char **subject_alt_names;

/* Encryption requirements */
int key_strength;
const EVP_MD *hash_fn;

/* Output Files */
char *ca_file;
char *ca_key_file;
char *cert_file;
char *cert_key_file;
struct sscg_options
{
/* How noisy to be when printing information */
enum sscg_verbosity verbosity;

/* Whether to print the version and exit */
bool print_version;

/* How long should certificates be valid (in days) */
int lifetime;

/* Subject information */
const char *country;
const char *state;
const char *locality;
const char *org;
const char *org_unit;
const char *email;
const char *hostname;
char **subject_alt_names;

/* Encryption requirements */
int key_strength;
const EVP_MD *hash_fn;

/* Output Files */
char *ca_file;
char *ca_key_file;
char *cert_file;
char *cert_key_file;
};

#endif /* _SSCG_H */
Loading

0 comments on commit 029db57

Please sign in to comment.