Skip to content

Commit

Permalink
chore(capi): Migrate examples to C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Nov 10, 2024
1 parent 521a8a8 commit 95b2270
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install libcli11-dev libfmt-dev meson
sudo apt-get install libcli11-dev meson
meson -v
- name: Setup just
uses: extractions/setup-just@v2
Expand Down
1 change: 0 additions & 1 deletion crates/capi/examples/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Checks: "clang-diagnostic-*,clang-analyzer-*"
WarningsAsErrors: ""
HeaderFilterRegex: ""
AnalyzeTemporaryDtors: false
FormatStyle: none
User: user
CheckOptions:
Expand Down
12 changes: 6 additions & 6 deletions crates/capi/examples/decrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// An example of decrypting a file from the abcrypt encrypted data format.

#include <fmt/core.h>
#include <termios.h>
#include <unistd.h>

Expand All @@ -13,6 +12,7 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <format>
#include <fstream>
#include <iostream>
#include <iterator>
Expand All @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {

std::ifstream input_file(input_filename);
if (!input_file) {
std::clog << fmt::format("Error: could not open {}: {}", input_filename,
std::clog << std::format("Error: could not open {}: {}", input_filename,
std::strerror(errno))
<< std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -68,18 +68,18 @@ int main(int argc, char *argv[]) {
std::string error_message(buf.cbegin(), buf.cend());
switch (error_code) {
case ABCRYPT_ERROR_CODE_INVALID_HEADER_MAC:
std::clog << fmt::format("Error: passphrase is incorrect: {}",
std::clog << std::format("Error: passphrase is incorrect: {}",
error_message)
<< std::endl;
break;
case ABCRYPT_ERROR_CODE_INVALID_MAC:
std::clog << fmt::format("Error: the encrypted data is corrupted: {}",
std::clog << std::format("Error: the encrypted data is corrupted: {}",
error_message)
<< std::endl;
break;
default:
std::clog
<< fmt::format(
<< std::format(
"Error: the header in the encrypted data is invalid: {}",
error_message)
<< std::endl;
Expand All @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
auto ofn = output_filename.value();
std::ofstream output_file(ofn);
if (!output_file) {
std::clog << fmt::format("Error: could not open {}: {}", ofn,
std::clog << std::format("Error: could not open {}: {}", ofn,
std::strerror(errno))
<< std::endl;
return EXIT_FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions crates/capi/examples/encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// An example of encrypting a file to the abcrypt encrypted data format.

#include <fmt/core.h>
#include <termios.h>
#include <unistd.h>

Expand All @@ -13,6 +12,7 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <format>
#include <fstream>
#include <iostream>
#include <iterator>
Expand Down Expand Up @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {

std::ifstream input_file(input_filename);
if (!input_file) {
std::clog << fmt::format("Error: could not open {}: {}", input_filename,
std::clog << std::format("Error: could not open {}: {}", input_filename,
std::strerror(errno))
<< std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -84,13 +84,13 @@ int main(int argc, char *argv[]) {
std::vector<std::uint8_t> buf(abcrypt_error_message_out_len(error_code));
abcrypt_error_message(error_code, buf.data(), buf.size());
std::string error_message(buf.cbegin(), buf.cend());
std::clog << fmt::format("Error: {}", error_message) << std::endl;
std::clog << std::format("Error: {}", error_message) << std::endl;
return EXIT_FAILURE;
}

std::ofstream output_file(output_filename);
if (!output_file) {
std::clog << fmt::format("Error: could not open {}: {}", output_filename,
std::clog << std::format("Error: could not open {}: {}", output_filename,
std::strerror(errno))
<< std::endl;
return EXIT_FAILURE;
Expand Down
9 changes: 4 additions & 5 deletions crates/capi/examples/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

// An example of reading the Argon2 parameters from a file.

#include <fmt/core.h>

#include <CLI/CLI.hpp>
#include <cerrno>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <format>
#include <fstream>
#include <iostream>
#include <iterator>
Expand All @@ -33,7 +32,7 @@ int main(int argc, char *argv[]) {
auto ifn = input_filename.value();
std::ifstream input_file(ifn);
if (!input_file) {
std::clog << fmt::format("Error: could not open {}: {}", ifn,
std::clog << std::format("Error: could not open {}: {}", ifn,
std::strerror(errno))
<< std::endl;
return EXIT_FAILURE;
Expand All @@ -52,7 +51,7 @@ int main(int argc, char *argv[]) {
std::vector<std::uint8_t> buf(abcrypt_error_message_out_len(error_code));
abcrypt_error_message(error_code, buf.data(), buf.size());
std::string error_message(buf.cbegin(), buf.cend());
std::clog << fmt::format(
std::clog << std::format(
"Error: data is not a valid abcrypt encrypted file: {}",
error_message)
<< std::endl;
Expand All @@ -64,7 +63,7 @@ int main(int argc, char *argv[]) {
auto parallelism = abcrypt_params_parallelism(params);
abcrypt_params_free(params);

std::cout << fmt::format(
std::cout << std::format(
"Parameters used: memoryCost = {}; timeCost = {}; "
"parallelism = {};",
memory_cost, time_cost, parallelism)
Expand Down
4 changes: 2 additions & 2 deletions crates/capi/examples/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

project('abcrypt_capi_examples',
'cpp',
default_options: ['warning_level=3', 'cpp_std=c++17'],
default_options: ['warning_level=3', 'cpp_std=c++20'],
license: 'Apache-2.0 OR MIT',
meson_version: '>=0.53.0',
version: '0.3.2',
Expand All @@ -16,7 +16,7 @@ cpp = meson.get_compiler('cpp')
cpp.check_header('termios.h', required: true)
cpp.check_header('unistd.h', required: true)

deps = [dependency('CLI11'), dependency('fmt')]
deps = dependency('CLI11')

libdir = meson.current_source_dir() / '../../../target'
if fs.exists(libdir / 'release')
Expand Down

0 comments on commit 95b2270

Please sign in to comment.