Skip to content

Commit ba32e51

Browse files
authored
Refactor C headers into nat20/types.h (#79)
Move common C headers into nat20/types.h so that necessary target platform customizations can be made in one place. Also add nat20/endian.h and nat20/limits.h and replace the posix type ssize_t with the C type ptrdiff_t.
1 parent 813313a commit ba32e51

File tree

24 files changed

+96
-49
lines changed

24 files changed

+96
-49
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ set(LIBNAT20_PUB_HEADERS
8989
include/nat20/cbor.h
9090
include/nat20/constants.h
9191
include/nat20/crypto.h
92+
include/nat20/endian.h
9293
include/nat20/error.h
9394
include/nat20/functionality.h
95+
include/nat20/limits.h
9496
include/nat20/oid.h
9597
include/nat20/open_dice.h
9698
include/nat20/stream.h

include/nat20/asn1.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include <nat20/oid.h>
2020
#include <nat20/stream.h>
2121
#include <nat20/types.h>
22-
#include <stdbool.h>
23-
#include <stdint.h>
24-
#include <unistd.h>
2522

2623
/** @file */
2724

include/nat20/cbor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#include <nat20/stream.h>
2020
#include <nat20/types.h>
21-
#include <stdint.h>
22-
#include <unistd.h>
2321

2422
#ifdef __cplusplus
2523
extern "C" {

include/nat20/crypto.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
#include <nat20/error.h>
2222
#include <nat20/types.h>
23-
#include <stdint.h>
24-
#include <unistd.h>
2523

2624
#ifdef __cplusplus
2725
extern "C" {

include/nat20/crypto/nat20/sha.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#pragma once
2828

2929
#include <nat20/types.h>
30-
#include <stddef.h>
31-
#include <stdint.h>
3230

3331
#ifdef __cplusplus
3432
extern "C" {

include/nat20/endian.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2026 Aurora Operations, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** @file Homogeneous Endian definitions for various environments. */
18+
19+
#pragma once
20+
21+
#ifdef __KERNEL__
22+
#include <asm/byteorder.h>
23+
#ifdef __LITTLE_ENDIAN
24+
#define LITTLE_ENDIAN __LITTLE_ENDIAN
25+
#define BIG_ENDIAN (~(__LITTLE_ENDIAN))
26+
#define BYTE_ORDER __LITTLE_ENDIAN
27+
#else
28+
#define LITTLE_ENDIAN (~(__BIG_ENDIAN))
29+
#define BIG_ENDIAN __BIG_ENDIAN
30+
#define BYTE_ORDER __BIG_ENDIAN
31+
#endif
32+
#else
33+
#include <endian.h>
34+
#endif

include/nat20/functionality.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include <nat20/types.h>
2727
#include <nat20/x509.h>
2828
#include <nat20/x509_ext_open_dice_input.h>
29-
#include <stddef.h>
30-
#include <stdint.h>
3129

3230
#ifdef __cplusplus
3331
extern "C" {

include/nat20/limits.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2026 Aurora Operations, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** @file Homogeneous Limits definitions for various environments. */
18+
19+
#pragma once
20+
21+
#ifdef __KERNEL__
22+
#include <linux/limits.h>
23+
#else
24+
#include <limits.h>
25+
#endif

include/nat20/oid.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
#pragma once
1818

19-
#include <stdbool.h>
20-
#include <stdint.h>
21-
#include <unistd.h>
19+
#include <nat20/types.h>
2220

2321
/** @file
2422
*

include/nat20/service/messages.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <nat20/crypto.h>
2121
#include <nat20/open_dice.h>
2222
#include <nat20/types.h>
23-
#include <stddef.h>
2423

2524
#ifdef __cplusplus
2625
extern "C" {

0 commit comments

Comments
 (0)