Skip to content

Commit

Permalink
Reorganize header files.
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdafu committed Jan 9, 2018
1 parent 155d5c1 commit 1b32a12
Show file tree
Hide file tree
Showing 84 changed files with 551 additions and 582 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINAR
add_subdirectory(${CMAKE_SOURCE_DIR}/legacy)
add_subdirectory(${CMAKE_SOURCE_DIR}/lib)
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_SOURCE_DIR}/tests)


# get all project files
Expand Down
7 changes: 7 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ You can run `make pretty` to reformat all source code lines. Some
legacy files are not stable under this operation, unfortunately.
There is no CI for source formatting yet for this reason.

## Directory Layout

Header files and unit tests are located next to the source file.
Header files are copied to `build/include/neopg` and
`build/include/neopg-tool` in a flat directory. This is a bit
unorthodox, but makes it easier to edit them along with the source
file. Integration tests are located in the tests/ directory.

## Translations

Expand Down
4 changes: 2 additions & 2 deletions legacy/gnupg/agent/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <time.h>

#include <botan/rfc3394.h>
#include <neopg/crypto/rng.h>
#include <neopg/rng.h>

#include "agent.h"

Expand Down Expand Up @@ -86,7 +86,7 @@ static gpg_error_t init_encryption(void) {
if (encryption_handle) return 0;

encryption_handle =
new Botan::SymmetricKey(*NeoPG::Crypto::rng(), ENCRYPTION_KEYSIZE);
new Botan::SymmetricKey(*NeoPG::rng(), ENCRYPTION_KEYSIZE);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion legacy/gnupg/common/gettime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "gettime.h"
#include "util.h"

#include <neopg/utils/time.h>
#include <neopg/time.h>
#define timegm NeoPG::timegm

#ifdef HAVE_UNSIGNED_TIME_T
Expand Down
4 changes: 2 additions & 2 deletions legacy/gnupg/common/keyserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#ifndef GNUPG_COMMON_KEYSERVER_H
#define GNUPG_COMMON_KEYSERVER_H

#include <neopg/proto/uri.h>
#include <neopg/uri.h>
#include <string>
#include <vector>

Expand All @@ -55,7 +55,7 @@
#define KEYSERVER_SCHEME_NOT_FOUND 127

struct keyserver_spec {
NeoPG::Proto::URI uri;
NeoPG::URI uri;
std::vector<std::string> options;
bool direct_uri;
};
Expand Down
10 changes: 5 additions & 5 deletions legacy/gnupg/dirmngr/crlfetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <errno.h>
#include <stdio.h>

#include <neopg/proto/http.h>
#include <neopg/http.h>

#include "crlfetch.h"

Expand All @@ -36,7 +36,7 @@ gpg_error_t crl_fetch(ctrl_t ctrl, const char *url, ksba_reader_t *reader) {

if (!url) return GPG_ERR_INV_ARG;

NeoPG::Proto::URI uri(url);
NeoPG::URI uri(url);
if (uri.scheme != "http")
/* Let the LDAP code try other schemes. FIXME: We removed LDAP
support. But curl can speak LDAP, so maybe use that. */
Expand All @@ -53,7 +53,7 @@ gpg_error_t crl_fetch(ctrl_t ctrl, const char *url, ksba_reader_t *reader) {
return GPG_ERR_NOT_SUPPORTED;
}

NeoPG::Proto::Http request;
NeoPG::Http request;
request.set_url(url).forbid_reuse().set_timeout(ctrl->timeout).no_cache();

if (opt.http_proxy)
Expand All @@ -62,9 +62,9 @@ gpg_error_t crl_fetch(ctrl_t ctrl, const char *url, ksba_reader_t *reader) {
request.default_proxy(opt.honor_http_proxy);

if (opt.disable_ipv6)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv4);
request.set_ipresolve(NeoPG::Http::Resolve::IPv4);
else if (opt.disable_ipv4)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv6);
request.set_ipresolve(NeoPG::Http::Resolve::IPv6);

try {
response = request.fetch();
Expand Down
10 changes: 5 additions & 5 deletions legacy/gnupg/dirmngr/ks-engine-hkp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <stdlib.h>
#include <string.h>

#include <neopg/proto/http.h>
#include <neopg/http.h>

#include "../common/userids.h"
#include "dirmngr.h"
Expand Down Expand Up @@ -110,7 +110,7 @@ static gpg_error_t send_request(ctrl_t ctrl, const std::string &url,
return GPG_ERR_NOT_SUPPORTED;
}

NeoPG::Proto::Http request;
NeoPG::Http request;
request.set_url(url).forbid_reuse().set_timeout(ctrl->timeout).no_cache();

if (opt.http_proxy)
Expand All @@ -119,17 +119,17 @@ static gpg_error_t send_request(ctrl_t ctrl, const std::string &url,
request.default_proxy(opt.honor_http_proxy);

if (opt.disable_ipv6)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv4);
request.set_ipresolve(NeoPG::Http::Resolve::IPv4);
else if (opt.disable_ipv4)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv6);
request.set_ipresolve(NeoPG::Http::Resolve::IPv6);

if (post_data) /* x-www-form-urlencoded is default */
request.set_post(post_data);

/* SSL Config. It all boils down to a simple switch: Normally, we
use the system CA list. And for the SKS Poolserver, we take a
baked in CA. */
NeoPG::Proto::URI uri(url);
NeoPG::URI uri(url);
if (uri.host == "hkps.pool.sks-keyservers.net") {
char *pemname =
make_filename_try(gnupg_datadir(), "sks-keyservers.netCA.pem", NULL);
Expand Down
8 changes: 4 additions & 4 deletions legacy/gnupg/dirmngr/ks-engine-http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdlib.h>
#include <string.h>

#include <neopg/proto/http.h>
#include <neopg/http.h>

#include "dirmngr.h"
#include "ks-engine.h"
Expand Down Expand Up @@ -69,7 +69,7 @@ gpg_error_t ks_http_fetch(ctrl_t ctrl, const char *url, std::string &response) {

/* Note that we only use the system provided certificates. */
/* ctrl->http_no_crl support? */
NeoPG::Proto::Http request;
NeoPG::Http request;
request.set_url(url).forbid_reuse().set_timeout(ctrl->timeout).no_cache();

if (opt.http_proxy)
Expand All @@ -78,9 +78,9 @@ gpg_error_t ks_http_fetch(ctrl_t ctrl, const char *url, std::string &response) {
request.default_proxy(opt.honor_http_proxy);

if (opt.disable_ipv6)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv4);
request.set_ipresolve(NeoPG::Http::Resolve::IPv4);
else if (opt.disable_ipv4)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv6);
request.set_ipresolve(NeoPG::Http::Resolve::IPv6);

try {
response = request.fetch();
Expand Down
8 changes: 4 additions & 4 deletions legacy/gnupg/dirmngr/ocsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdio.h>
#include <stdlib.h>

#include <neopg/proto/http.h>
#include <neopg/http.h>

#include "certcache.h"
#include "dirmngr.h"
Expand Down Expand Up @@ -150,7 +150,7 @@ static gpg_error_t do_ocsp_request(ctrl_t ctrl, ksba_ocsp_t ocsp,
return err;
}

NeoPG::Proto::Http request;
NeoPG::Http request;
request.set_url(url).forbid_reuse().set_timeout(ctrl->timeout).no_cache();

if (opt.http_proxy)
Expand All @@ -159,9 +159,9 @@ static gpg_error_t do_ocsp_request(ctrl_t ctrl, ksba_ocsp_t ocsp,
request.default_proxy(opt.honor_http_proxy);

if (opt.disable_ipv6)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv4);
request.set_ipresolve(NeoPG::Http::Resolve::IPv4);
else if (opt.disable_ipv4)
request.set_ipresolve(NeoPG::Proto::Http::Resolve::IPv6);
request.set_ipresolve(NeoPG::Http::Resolve::IPv6);

request.m_header["Content-Type"] = "application/ocsp-request";
request.set_post(post, postlen);
Expand Down
6 changes: 3 additions & 3 deletions legacy/libgcrypt/random/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@

#include <config.h>

#include <neopg/crypto/rng.h>
#include <neopg/rng.h>

#include "g10lib.h"

/* --- Functions --- */

/* Add BUFLEN bytes from BUF to the internal random pool. */
gpg_error_t _gcry_random_add_bytes(const void *buf, size_t buflen) {
NeoPG::Crypto::rng()->add_entropy((Botan::byte *)buf, buflen);
NeoPG::rng()->add_entropy((Botan::byte *)buf, buflen);
return 0;
}

static void do_randomize(void *buffer, size_t length) {
NeoPG::Crypto::rng()->randomize((Botan::byte *)buffer, length);
NeoPG::rng()->randomize((Botan::byte *)buffer, length);
}

/* The public function to return random data.
Expand Down
99 changes: 65 additions & 34 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,50 @@ FIND_PACKAGE(Boost COMPONENTS date_time REQUIRED)

set(NEOPG_INCLUDE ../include)

set(NeopgHeaders
crypto/rng.h
openpgp/compressed_data_packet.h
openpgp/literal_data_packet.h
openpgp/marker_packet.h
openpgp/modification_detection_code_packet.h
openpgp/packet_header.h
openpgp/packet.h
openpgp/symmetrically_encrypted_data_packet.h
openpgp/symmetrically_encrypted_integrity_protected_data_packet.h
openpgp/trust_packet.h
openpgp/user_attribute_packet.h
openpgp/user_id_packet.h
parser/openpgp.h
proto/http.h
proto/uri.h
utils/common.h
utils/stream.h
utils/time.h
)
add_library(neopg
../include/neopg/crypto/rng.h
../include/neopg/openpgp/header.h
../include/neopg/openpgp/literal_data_packet.h
../include/neopg/openpgp/marker_packet.h
../include/neopg/openpgp/packet.h
../include/neopg/openpgp/user_id_packet.h
../include/neopg/openpgp/user_attribute_packet.h
../include/neopg/openpgp/modification_detection_code_packet.h
../include/neopg/openpgp/symmetrically_encrypted_integrity_protected_data_packet.h
../include/neopg/openpgp/symmetrically_encrypted_data_packet.h
../include/neopg/openpgp/compressed_data_packet.h
../include/neopg/openpgp/trust_packet.h
../include/neopg/parser/openpgp.h
../include/neopg/proto/uri.h
../include/neopg/proto/http.h
../include/neopg/utils/time.h
utils/time.cpp
utils/stream.cpp
crypto/rng.cpp
openpgp/header.cpp
openpgp/compressed_data_packet.cpp
openpgp/literal_data_packet.cpp
openpgp/marker_packet.cpp
openpgp/packet.cpp
openpgp/user_id_packet.cpp
openpgp/user_attribute_packet.cpp
openpgp/modification_detection_code_packet.cpp
openpgp/symmetrically_encrypted_integrity_protected_data_packet.cpp
openpgp/packet_header.cpp
openpgp/packet.cpp
openpgp/symmetrically_encrypted_data_packet.cpp
openpgp/compressed_data_packet.cpp
openpgp/symmetrically_encrypted_integrity_protected_data_packet.cpp
openpgp/trust_packet.cpp
proto/uri.cpp
openpgp/user_attribute_packet.cpp
openpgp/user_id_packet.cpp
proto/http.cpp
proto/uri.cpp
utils/stream.cpp
utils/time.cpp
)
target_include_directories(neopg PUBLIC
"${CMAKE_BINARY_DIR}/include"
${PEGTL_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${BOTAN2_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
)

target_compile_options(neopg
Expand All @@ -50,16 +61,36 @@ target_compile_options(neopg
${BOTAN2_CFLAGS_OTHER}
)

target_include_directories(neopg PUBLIC
${NEOPG_INCLUDE}
${PEGTL_INCLUDE_DIR}
${GTEST_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${BOTAN2_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
)

target_link_libraries(neopg PUBLIC
${BOTAN2_LDFLAGS} ${BOTAN2_LIBRARIES}
${CURL_LDFLAGS} ${CURL_LIBRARIES}
)

# Publish header files for libneopg
set(NeopgPublishedHeaders "")
set(NeopgPublishedHeadersDir "${CMAKE_BINARY_DIR}/include/neopg")

foreach(Header IN LISTS NeopgHeaders)
get_filename_component(HeaderFilename "${Header}" NAME)
set(Output "${NeopgPublishedHeadersDir}/${HeaderFilename}")
list(APPEND NeopgPublishedHeaders "${Output}")
add_custom_command(
OUTPUT "${Output}"
COMMAND "${CMAKE_COMMAND}" -E
make_directory "${NeopgPublishedHeadersDir}"
COMMAND "${CMAKE_COMMAND}" -E
copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${Header}" "${Output}"
MAIN_DEPENDENCY "${Header}"
COMMENT "Publishing ${HeaderFilename}"
VERBATIM
)
endforeach()
add_custom_target(
neopg_headers
DEPENDS ${NeopgPublishedHeaders}
SOURCES ${NeopgHeaders}
)

add_dependencies(neopg neopg_headers)

add_subdirectory(tests)
4 changes: 1 addition & 3 deletions lib/crypto/rng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
*/

#include <botan/auto_rng.h>
#include <neopg/crypto/rng.h>
#include <neopg/rng.h>

namespace NeoPG {
namespace Crypto {

Botan::RandomNumberGenerator* rng(void) {
static thread_local Botan::RandomNumberGenerator* rng_local;
Expand All @@ -19,5 +18,4 @@ Botan::RandomNumberGenerator* rng(void) {
return rng_local;
}

} // Namespace CLI
} // Namespace NeoPG
2 changes: 0 additions & 2 deletions include/neopg/crypto/rng.h → lib/crypto/rng.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#include <neopg/common.h>

namespace NeoPG {
namespace Crypto {

NEOPG_DLL Botan::RandomNumberGenerator* rng(void);

} // Namespace CLI
} // Namespace NeoPG
Loading

0 comments on commit 1b32a12

Please sign in to comment.