Skip to content

Commit da06527

Browse files
Format all C source code using clang-format (#420)
This update adds a new `.clang-format` file that can be used to as a configuration file for the clang-format tool used to format the `C` code contained in this project. Code is formatted from both a stylistic and whitespace perspective. The `README.md` was updated to describe the rules and the tooling being used to format the `C` code. All `.c` and `.h` files within the project were formatted according to the rules contained in the `.clang-format` file. Additional options can be found in the documentation link found at: https://clang.llvm.org/docs/ClangFormatStyleOptions.html Signed-off-by: Jason Katonica <katonica@us.ibm.com>
1 parent 1bfb8b8 commit da06527

34 files changed

+11331
-10125
lines changed

.clang-format

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# Formatting rules for clang-format tool used by the OpenJCEPlus project.
3+
BasedOnStyle: Google
4+
UseTab: Never
5+
InsertBraces: True
6+
IndentWidth: 4
7+
SortIncludes: false
8+
ColumnLimit: 80
9+
AlignConsecutiveDeclarations: true
10+
AlignConsecutiveAssignments: true

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@
4242
/src/main/native/com_ibm_crypto_plus_provider_ock_*.h
4343

4444
# Files generated by tests.
45-
/0Test*.txt
45+
/0Test*.txt
46+
47+
# Allow tracked changes for configuration file used by the
48+
# clang-format tool for formatting C code.
49+
!.clang-format

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ Signature | SHA512withRSA |X |X
354354

355355
The following contribution guidelines should be followed:
356356

357-
1. Code should be styled according to the included [style.xml](style.xml) eclipse rules.
357+
1. Java code should be styled according to the included [style.xml](style.xml) eclipse rules.
358+
359+
1. C code should be styled using the clang-format tool using the included [.clang-format](.clang-format) rules.
358360

359361
1. A pull request should be sent for review only after the github action associated with this repository is automatically executed when a pull request is created.
360362

@@ -369,11 +371,9 @@ The following contribution guidelines should be followed:
369371
- You MUST validate that the use of the GenAI tool does not produce protected code (i.e. code that is copyrighted or licensed outside of our project's current licenses).
370372

371373
An example of a tagging would be:
372-
```console
373-
/* Start code generated by <GenAI tool> */
374374

375-
375+
```console
376+
/* Start code generated by <GenAI tool> */
376377

377378
/* End code generated by <GenAI tool> */
378-
```
379-
379+
```

src/main/native/BasicRandom.c

Lines changed: 94 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,43 @@
2323
* Method: RAND_nextBytes
2424
* Signature: (J[B)V
2525
*/
26-
JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1nextBytes
27-
(JNIEnv * env, jclass thisObj, jlong ockContextId, jbyteArray bytes)
28-
{
29-
static const char * functionName = "NativeInterface.RAND_nextbytes";
30-
31-
ICC_CTX * ockCtx = (ICC_CTX *)((intptr_t) ockContextId);
32-
unsigned char * bytesNative = NULL;
33-
jboolean isCopy;
34-
jint size;
35-
int rc = ICC_OK;
36-
37-
if( debug ) {
38-
gslogFunctionEntry(functionName);
39-
}
40-
41-
bytesNative = (*env)->GetPrimitiveArrayCritical(env, bytes, &isCopy);
42-
if( bytesNative == NULL ) {
43-
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
44-
} else {
45-
size = (*env)->GetArrayLength(env, bytes);
26+
JNIEXPORT void JNICALL
27+
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1nextBytes(
28+
JNIEnv *env, jclass thisObj, jlong ockContextId, jbyteArray bytes) {
29+
static const char *functionName = "NativeInterface.RAND_nextbytes";
30+
31+
ICC_CTX *ockCtx = (ICC_CTX *)((intptr_t)ockContextId);
32+
unsigned char *bytesNative = NULL;
33+
jboolean isCopy;
34+
jint size;
35+
int rc = ICC_OK;
36+
37+
if (debug) {
38+
gslogFunctionEntry(functionName);
39+
}
40+
41+
bytesNative = (*env)->GetPrimitiveArrayCritical(env, bytes, &isCopy);
42+
if (bytesNative == NULL) {
43+
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
44+
} else {
45+
size = (*env)->GetArrayLength(env, bytes);
4646
#ifdef DEBUG_RANDOM_DETAIL
47-
gslogMessage ("DETAIL_RANDOM size=%d", (int) size);
47+
gslogMessage("DETAIL_RANDOM size=%d", (int)size);
4848
#endif
49-
rc = ICC_RAND_bytes(ockCtx, bytesNative, size);
50-
if( rc != ICC_OSSL_SUCCESS ) {
51-
ockCheckStatus(ockCtx);
52-
throwOCKException(env, 0, "ICC_RAND_BYTES failed");
49+
rc = ICC_RAND_bytes(ockCtx, bytesNative, size);
50+
if (rc != ICC_OSSL_SUCCESS) {
51+
ockCheckStatus(ockCtx);
52+
throwOCKException(env, 0, "ICC_RAND_BYTES failed");
53+
}
5354
}
54-
}
5555

56-
if( bytesNative != NULL ) {
57-
(*env)->ReleasePrimitiveArrayCritical(env, bytes, bytesNative, 0);
58-
}
56+
if (bytesNative != NULL) {
57+
(*env)->ReleasePrimitiveArrayCritical(env, bytes, bytesNative, 0);
58+
}
5959

60-
if( debug ) {
61-
gslogFunctionExit(functionName);
62-
}
60+
if (debug) {
61+
gslogFunctionExit(functionName);
62+
}
6363
}
6464

6565
//============================================================================
@@ -68,39 +68,39 @@ JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAN
6868
* Method: RAND_setSeed
6969
* Signature: (J[B)V
7070
*/
71-
JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1setSeed
72-
(JNIEnv * env, jclass thisObj, jlong ockContextId, jbyteArray seed)
73-
{
74-
static const char * functionName = "NativeInterface.RAND_setSeed";
75-
76-
ICC_CTX * ockCtx = (ICC_CTX *)((intptr_t) ockContextId);
77-
unsigned char * seedNative = NULL;
78-
jboolean isCopy;
79-
jint size;
80-
81-
if( debug ) {
82-
gslogFunctionEntry(functionName);
83-
}
84-
85-
seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
86-
if( seedNative == NULL ) {
87-
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
88-
} else {
89-
size = (*env)->GetArrayLength(env, seed);
71+
JNIEXPORT void JNICALL
72+
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1setSeed(
73+
JNIEnv *env, jclass thisObj, jlong ockContextId, jbyteArray seed) {
74+
static const char *functionName = "NativeInterface.RAND_setSeed";
75+
76+
ICC_CTX *ockCtx = (ICC_CTX *)((intptr_t)ockContextId);
77+
unsigned char *seedNative = NULL;
78+
jboolean isCopy;
79+
jint size;
80+
81+
if (debug) {
82+
gslogFunctionEntry(functionName);
83+
}
84+
85+
seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
86+
if (seedNative == NULL) {
87+
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
88+
} else {
89+
size = (*env)->GetArrayLength(env, seed);
9090
#ifdef DEBUG_RANDOM_DETAIL
91-
gslogMessage ("DETAIL_RANDOM size=%d", (int) size);
91+
gslogMessage("DETAIL_RANDOM size=%d", (int)size);
9292
#endif
9393

94-
ICC_RAND_seed(ockCtx, seedNative, size);
95-
}
94+
ICC_RAND_seed(ockCtx, seedNative, size);
95+
}
9696

97-
if( seedNative != NULL ) {
98-
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
99-
}
97+
if (seedNative != NULL) {
98+
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
99+
}
100100

101-
if( debug ) {
102-
gslogFunctionExit(functionName);
103-
}
101+
if (debug) {
102+
gslogFunctionExit(functionName);
103+
}
104104
}
105105

106106
//============================================================================
@@ -109,43 +109,42 @@ JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAN
109109
* Method: RAND_generateSeed
110110
* Signature: (J[B)V
111111
*/
112-
JNIEXPORT void JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1generateSeed
113-
(JNIEnv * env, jclass thisObj, jlong ockContextId, jbyteArray seed)
114-
{
115-
static const char * functionName = "NativeInterface.RAND_generateSeed";
116-
117-
ICC_CTX * ockCtx = (ICC_CTX *)((intptr_t) ockContextId);
118-
unsigned char * seedNative = NULL;
119-
jboolean isCopy;
120-
jint size;
121-
ICC_STATUS status;
122-
123-
if( debug ) {
124-
gslogFunctionEntry(functionName);
125-
}
126-
127-
seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
128-
if( seedNative == NULL ) {
129-
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
130-
} else {
131-
size = (*env)->GetArrayLength(env, seed);
132-
133-
ICC_GenerateRandomSeed(ockCtx, &status, size, seedNative);
112+
JNIEXPORT void JNICALL
113+
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_RAND_1generateSeed(
114+
JNIEnv *env, jclass thisObj, jlong ockContextId, jbyteArray seed) {
115+
static const char *functionName = "NativeInterface.RAND_generateSeed";
116+
117+
ICC_CTX *ockCtx = (ICC_CTX *)((intptr_t)ockContextId);
118+
unsigned char *seedNative = NULL;
119+
jboolean isCopy;
120+
jint size;
121+
ICC_STATUS status;
122+
123+
if (debug) {
124+
gslogFunctionEntry(functionName);
125+
}
126+
127+
seedNative = (*env)->GetPrimitiveArrayCritical(env, seed, &isCopy);
128+
if (seedNative == NULL) {
129+
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!");
130+
} else {
131+
size = (*env)->GetArrayLength(env, seed);
132+
133+
ICC_GenerateRandomSeed(ockCtx, &status, size, seedNative);
134134
#ifdef DEBUG_RANDOM_DETAIL
135-
if( debug ) {
136-
gslogMessage ("DETAIL_RAND size=%d", (int) size);
137-
gslogMessagePrefix ("DETAIL_RAND size =%d", (int) size);
138-
gslogMessageHex ((char *)seedNative, 0, (int) size, 0, 0, NULL);
139-
}
135+
if (debug) {
136+
gslogMessage("DETAIL_RAND size=%d", (int)size);
137+
gslogMessagePrefix("DETAIL_RAND size =%d", (int)size);
138+
gslogMessageHex((char *)seedNative, 0, (int)size, 0, 0, NULL);
139+
}
140140
#endif
141-
}
141+
}
142142

143-
if( seedNative != NULL ) {
144-
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
145-
}
143+
if (seedNative != NULL) {
144+
(*env)->ReleasePrimitiveArrayCritical(env, seed, seedNative, 0);
145+
}
146146

147-
if( debug ) {
148-
gslogFunctionExit(functionName);
149-
}
147+
if (debug) {
148+
gslogFunctionExit(functionName);
149+
}
150150
}
151-

src/main/native/BuildDate.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,45 @@
2020
* Method: getLibraryBuildDate
2121
* Signature: ()Ljava/lang/String;
2222
*/
23-
JNIEXPORT jstring JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterface_getLibraryBuildDate
24-
(JNIEnv * env, jclass thisObj)
25-
{
26-
static const char * functionName = "NativeInterface.getLibraryBuildDate";
27-
const char * buildDateString = NULL;
28-
jstring retValue = NULL;
23+
JNIEXPORT jstring JNICALL
24+
Java_com_ibm_crypto_plus_provider_ock_NativeInterface_getLibraryBuildDate(
25+
JNIEnv* env, jclass thisObj) {
26+
static const char* functionName = "NativeInterface.getLibraryBuildDate";
27+
const char* buildDateString = NULL;
28+
jstring retValue = NULL;
2929

30-
if( debug ) {
31-
gslogFunctionEntry(functionName);
32-
}
30+
if (debug) {
31+
gslogFunctionEntry(functionName);
32+
}
3333

3434
#ifdef __MVS__
35-
#pragma convert("ISO8859-1")
35+
#pragma convert("ISO8859-1")
3636
#endif
3737

3838
#if defined(BUILD_DATE)
39-
// Compile flag specifying the build date
40-
buildDateString = BUILD_DATE;
39+
// Compile flag specifying the build date
40+
buildDateString = BUILD_DATE;
4141
#elif defined(__DATE__) && defined(__TIME__)
42-
// Pre-processor macros
43-
buildDateString = __DATE__ " " __TIME__;
42+
// Pre-processor macros
43+
buildDateString = __DATE__ " " __TIME__;
4444
#elif defined(__DATE__)
45-
// Pre-processor macro
46-
buildDateString = __DATE__;
45+
// Pre-processor macro
46+
buildDateString = __DATE__;
4747
#else
48-
buildDateString = "<UNKNOWN>";
48+
buildDateString = "<UNKNOWN>";
4949
#endif
5050

5151
#ifdef __MVS__
52-
#pragma convert(pop)
52+
#pragma convert(pop)
5353
#endif
5454

55-
if( buildDateString != NULL ) {
56-
retValue = (*env)->NewStringUTF(env, buildDateString);
57-
}
55+
if (buildDateString != NULL) {
56+
retValue = (*env)->NewStringUTF(env, buildDateString);
57+
}
5858

59-
if( debug ) {
60-
gslogFunctionExit(functionName);
61-
}
59+
if (debug) {
60+
gslogFunctionExit(functionName);
61+
}
6262

63-
return retValue;
63+
return retValue;
6464
}

0 commit comments

Comments
 (0)