Skip to content

Commit

Permalink
IWYU compliant code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofortina committed Oct 7, 2024
1 parent 79c73ba commit e93dd28
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 80 deletions.
26 changes: 5 additions & 21 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dist_doc_DATA = README.md LICENSE doc/API.md
# Custom script for generating files, but not installed
dist_noinst_SCRIPTS = autogen.sh

# Include all files inside doc/doxygen in the distribution tarball
# Include all files in the contrib, doc, and examples directories in the distribution tarball
EXTRA_DIST = \
$(wildcard contrib/*) \
$(wildcard doc/*) \
Expand All @@ -33,32 +33,16 @@ doc/doxygen/.stamp: doc/Doxyfile
# If Doxygen is available, build the documentation
if HAVE_DOXYGEN
docs: doc/doxygen/.stamp
else
docs:
@echo "error: doxygen not found"
endif

# Target to clean up the documentation directory
clean-docs:
@echo "Cleaning documentation files..."
rm -rf doc/doxygen

# Custom rule to install the entire 'doc' directory
install-data-local: docs
$(MKDIR_P) $(DESTDIR)$(docdir)
cp -r doc/doxygen/html $(DESTDIR)$(docdir)

# Remove the installed documentation directory during uninstallation.
uninstall-local:
-rm -rf $(DESTDIR)$(docdir)/html

# Ensure that make docs is run when creating a distribution
dist-hook:
$(MAKE) docs

else
docs:
@echo "error: doxygen not found"
clean-docs:
@echo "error: doxygen not found"
endif

# Custom clean rule to clean both docs and dist/ directory
clean-local: clean-docs
@echo "Cleaning dist directory..."
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = src/include/qyra.h src/include/common.h doc/README_doxygen.md
INPUT = src/include/qyra.h doc/README_doxygen.md

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
2 changes: 2 additions & 0 deletions examples/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <iostream>
#include <stdint.h>
#include <string>
#include <vector>

/**
* @brief Main function that initializes a CQYRA object, sets the header and nonce,
Expand Down
2 changes: 1 addition & 1 deletion examples/example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "../src/utils.h"
#include <qyra.h>

#include <cstdint>
#include <cstddef>
#include <iostream>
#include <sstream>
#include <stdexcept>
Expand Down
10 changes: 3 additions & 7 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ lib_LTLIBRARIES = libqyra.la
noinst_LTLIBRARIES =

# Header file to be installed for public API access
include_HEADERS = include/qyra.h include/common.h
include_HEADERS = include/qyra.h

# Include directories
QYRA_INCLUDES=-I$(builddir) -I$(srcdir)/include -I$(srcdir)/test -I$(srcdir)/bench
QYRA_INCLUDES=-I$(builddir) -I$(srcdir)/include -I$(srcdir)/test -I$(srcdir)/bench -I$(srcdir)/bench/data

QYRA_API_H = \
include/qyra.h

QYRA_COMMON_H = \
include/common.h

QYRA_H = \
crypto.h \
hash.h \
Expand All @@ -58,8 +55,7 @@ libqyra_la_SOURCES = \
utils.cpp \
qyra.cpp \
$(QYRA_H) \
$(QYRA_API_H) \
$(QYRA_COMMON_H)
$(QYRA_API_H)

# Preprocessor flags for libqyra
libqyra_la_CPPFLAGS = $(AM_CPPFLAGS) $(QYRA_INCLUDES)
Expand Down
3 changes: 1 addition & 2 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ QYRA_BENCH = \
utils.cpp \
bench/bench.h \
bench/bench.cpp \
$(QYRA_H) \
$(QYRA_COMMON_H)
$(QYRA_H)

# Specify source files for the qyra-bench program
bench_qyra_bench_SOURCES = \
Expand Down
14 changes: 10 additions & 4 deletions src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <bench.h>
#include <common.h>
#include <data/solutions.json.h>
#include <fstream>

#include <graph.h>
#include <path.h>
#include <qyra.h>
#include <stream.h>
#include <utils.h>

#include <chrono>
#include <data/solutions.json.h>

// IWYU pragma: no_include <bits/chrono.h>

#include <chrono> // IWYU pragma: keep
#include <cstdio>
#include <iostream>
#include <limits>
#include <random>
#include <string>
#include <thread>
#include <vector>

Expand Down
4 changes: 3 additions & 1 deletion src/bench/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#ifndef QYRA_BENCH_H
#define QYRA_BENCH_H

// IWYU pragma: no_include <oqs/kem_kyber.h>

#include <cstdint>
#include <oqs/oqs.h>
#include <oqs/oqs.h> // IWYU pragma: keep

// Public key.
uint8_t publicKey[OQS_KEM_kyber_768_length_public_key] =
Expand Down
14 changes: 8 additions & 6 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <crypto.h>

#include <utils.h>

#include <algorithm>
// IWYU pragma: no_include <oqs/common.h>
// IWYU pragma: no_include <oqs/kem_kyber.h>

#include <openssl/evp.h>
#include <openssl/rand.h>
#include <oqs/oqs.h>
#include <random>
#include <stdexcept>
#include <openssl/types.h>
#include <oqs/oqs.h> // IWYU pragma: keep
#include <stdio.h>
#include <string>
#include <vector>

#include <iostream>

// Static method to generate a public/secret key pair for encryption.
bool CCrypter::GenerateKeyPair(uint8_t* public_key, uint8_t* secret_key)
{
Expand Down
1 change: 0 additions & 1 deletion src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define QYRA_CRYPTO_H

#include <cstdint>
#include <string>
#include <vector>

/**
Expand Down
20 changes: 7 additions & 13 deletions src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <common.h>
#include <crypto.h>
#include <graph.h>

#include <crypto.h>
#include <hash.h>
#include <qyra.h>
#include <stream.h>
#include <utils.h>

#include <algorithm>
#include <array>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <stdio.h>
#include <thread>
#include <unordered_set>
#include <utility>

// Constructor of the CGraph class.
// Initializes the adjacency matrix with a maximum number of nodes.
Expand Down Expand Up @@ -51,15 +52,8 @@ bool CGraph::AddEdge(uint16_t from, uint16_t to)
// Reset the bitset for the 'from' node, clearing all edges from this node.
adjacencyMatrix[from].reset();

try {
// Set the bit indicating an edge from 'from' to 'to'.
adjacencyMatrix[from].set(to);
} catch (const std::exception& e) {
fprintf(stderr, "ERROR: [%s] Failed to set edge from %u to %u: %s\n", __func__, from, to, e.what());

// Return false on failure
return false;
}
// Set the bit indicating an edge from 'from' to 'to'.
adjacencyMatrix[from].set(to);

// Return true on success
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#ifndef QYRA_GRAPH_H
#define QYRA_GRAPH_H

// IWYU pragma: no_include <oqs/kem_kyber.h>

#include <bitset>
#include <oqs/oqs.h>
#include <cstddef>
#include <oqs/oqs.h> // IWYU pragma: keep
#include <stdint.h>
#include <string>
#include <vector>

Expand Down
1 change: 0 additions & 1 deletion src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef QYRA_HASH_H
#define QYRA_HASH_H

#include <string>
#include <vector>

/**
Expand Down
47 changes: 45 additions & 2 deletions src/include/qyra.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#ifndef QYRA_H
#define QYRA_H

#include <common.h>

#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
Expand All @@ -21,9 +20,53 @@
#endif
#endif

/**
* @brief Explanation of data structure sizes for encryption
*
* The plaintext consists of two parts:
* - **Header**: 108 bytes
* - **Nonce**: 32 bytes
*
* Together, this makes a total of 140 bytes of plaintext data.
*
* Since AES-256-CBC operates in 16-byte blocks, and the plaintext size is not a multiple of 16,
* 4 bytes of padding will be added to reach a size of 144 bytes.
*
* The encrypted version of this 140-byte plaintext will always be 144 bytes due to padding.
*/
#define ENC_SIZE 144 ///< Size of encrypted data
#define IV_SIZE 16 ///< Size of initialization vector (AES_BLOCK_SIZE)
#define CIPHERTEXT_SIZE 1088 ///< Size of ciphertext for Kyber768
#define HASH_SIZE 32 ///< Size of hash

#define TOTAL_SIZE (ENC_SIZE + IV_SIZE + CIPHERTEXT_SIZE) ///< Define total size for the combined vector
#define SOLUTION_SIZE (TOTAL_SIZE + HASH_SIZE) ///< Define total size for the solution vector including the hash

/**
* @class CGraph
* @brief Forward declaration of the CGraph class.
*
* This class represents a graph structure used in various graph algorithms.
*/
class CGraph;

/**
* @class CPath
* @brief Forward declaration of the CPath class.
*
* This class is used to represent a path within a graph, enabling
* traversal and pathfinding operations.
*/
class CPath;

/**
* @namespace LibQYRA
* @brief A namespace for the LibQYRA library.
*
* This namespace encompasses all classes and functions
* related to the LibQYRA library, providing modularity and
* preventing name collisions.
*/
namespace LibQYRA {

/**
Expand Down
6 changes: 5 additions & 1 deletion src/keygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

#include <crypto.h>

// IWYU pragma: no_include <oqs/kem_kyber.h>

#include <cstddef>
#include <iomanip>
#include <iostream>
#include <oqs/oqs.h>
#include <oqs/oqs.h> // IWYU pragma: keep
#include <stdint.h>

int main()
{
Expand Down
9 changes: 4 additions & 5 deletions src/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <crypto.h>
#include <path.h>

#include <graph.h>
#include <hash.h>
#include <path.h>
#include <stream.h>
#include <utils.h>

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <mutex>
#include <numeric>
#include <sstream>
#include <thread>

// Constructs a CPath from a set of nodes.
Expand Down
1 change: 1 addition & 0 deletions src/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef QYRA_PATH_H
#define QYRA_PATH_H

#include <cstddef>
#include <cstdint>
#include <mutex>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions src/qyra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stream.h>
#include <utils.h>

#include <stdio.h>
#include <thread>
#include <vector>

Expand Down
6 changes: 1 addition & 5 deletions src/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

#include <test.h>

#include <crypto.h>
#include <utils.h>

#include <boost/test/included/unit_test.hpp> // IWYU pragma: keep
#include <vector>

#include <boost/test/included/unit_test.hpp>

BasicTestingSetup::BasicTestingSetup()
{
originalData = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'};
Expand Down
Loading

0 comments on commit e93dd28

Please sign in to comment.