Compare commits
15 Commits
1.0.1
...
085f182357
| Author | SHA1 | Date | |
|---|---|---|---|
| 085f182357 | |||
| bce26d3a4b | |||
| 44120b7ebb | |||
| 87a0cce29d | |||
| 9f939fea24 | |||
| 8da5ce49ef | |||
| b0e645679d | |||
| 6d689cb9b3 | |||
| 119bca6c87 | |||
| 5396abe202 | |||
| 5f2cffdd82 | |||
| 93baa83f87 | |||
| b6780fe572 | |||
| bb98575fb9 | |||
| 98fa49bd06 |
10
.github/workflows/docs.yml
vendored
10
.github/workflows/docs.yml
vendored
@ -4,8 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pages: write
|
pages: write
|
||||||
@ -24,12 +22,16 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
- name: Setup Pages
|
- name: Setup Pages
|
||||||
uses: actions/configure-pages@v5
|
uses: actions/configure-pages@v5
|
||||||
- name: Install Doxygen
|
- name: Install Doxygen
|
||||||
run: sudo apt install doxygen
|
run: |
|
||||||
|
wget https://github.com/doxygen/doxygen/releases/download/Release_1_12_0/doxygen-1.12.0.linux.bin.tar.gz
|
||||||
|
tar -xf doxygen-1.12.0.linux.bin.tar.gz
|
||||||
- name: Generate docs
|
- name: Generate docs
|
||||||
run: doxygen
|
run: ./doxygen-1.12.0/bin/doxygen
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -43,6 +43,7 @@ bin
|
|||||||
obj
|
obj
|
||||||
lib
|
lib
|
||||||
doc
|
doc
|
||||||
|
cov
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.vscode
|
.vscode
|
||||||
|
|||||||
2
AUTHORS
2
AUTHORS
@ -1,5 +1,5 @@
|
|||||||
libbasen project authors:
|
libbasen project authors:
|
||||||
|
|
||||||
commits | username
|
commits | username
|
||||||
46 | vSEK1RO
|
70 | vSEK1RO
|
||||||
|
|
||||||
|
|||||||
2
Doxyfile
2
Doxyfile
@ -48,7 +48,7 @@ PROJECT_NAME = libbasen
|
|||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = v1.0.1
|
PROJECT_NUMBER = v1.0.2
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewer a
|
# for a project that appears at the top of each page and should give viewer a
|
||||||
|
|||||||
19
Makefile
19
Makefile
@ -5,7 +5,7 @@ DEBUG ?= false
|
|||||||
USRDIR ?= /usr
|
USRDIR ?= /usr
|
||||||
|
|
||||||
.PHONY: build i install uni uninstall\
|
.PHONY: build i install uni uninstall\
|
||||||
tools library tests docs clean
|
tools library tests docs cov clean
|
||||||
|
|
||||||
LIB = basen
|
LIB = basen
|
||||||
OBJS =\
|
OBJS =\
|
||||||
@ -15,7 +15,7 @@ OBJS =\
|
|||||||
base64\
|
base64\
|
||||||
hash/sha256\
|
hash/sha256\
|
||||||
|
|
||||||
TOOLS =\
|
TOOLS = ${LIB}
|
||||||
|
|
||||||
TESTS =\
|
TESTS =\
|
||||||
test-hex\
|
test-hex\
|
||||||
@ -59,6 +59,8 @@ DIRS =\
|
|||||||
${OBJDIR}\
|
${OBJDIR}\
|
||||||
${OBJDIR}/hash\
|
${OBJDIR}/hash\
|
||||||
${LIBDIR}\
|
${LIBDIR}\
|
||||||
|
doc\
|
||||||
|
cov
|
||||||
|
|
||||||
build: library tools
|
build: library tools
|
||||||
|
|
||||||
@ -80,8 +82,19 @@ uninstall:
|
|||||||
docs:
|
docs:
|
||||||
doxygen Doxyfile
|
doxygen Doxyfile
|
||||||
|
|
||||||
|
cover: ${DIRS} ${patsubst %, ${BINDIR}/%${-g}-cov, ${TESTS}}
|
||||||
|
rm -f **/*.gcda
|
||||||
|
${patsubst %, ./${BINDIR}/%${-g}-cov;, ${TESTS}}
|
||||||
|
gcovr --html-nested cov/index.html --txt --exclude-throw-branches
|
||||||
|
|
||||||
|
${OBJDIR}/%${-g}-cov.o: ${SRCDIR}/%.cpp ${INCDIR}/${LIB}/%.hpp
|
||||||
|
${CC} -o $@ -c $< -I${INCDIR} ${-l} ${CFLAGS} --coverage
|
||||||
|
|
||||||
|
${BINDIR}/%${-g}-cov: ${TESTDIR}/%.cpp ${patsubst %, ${OBJDIR}/%${-g}-cov.o, ${OBJS}}
|
||||||
|
${CC} -o $@ $^ -I${INCDIR} ${-l} -lgtest -lgcov ${CFLAGS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf ${OBJDIR}/* ${LIBDIR}/* ${BINDIR}/*
|
rm -rf ${DIRS}
|
||||||
|
|
||||||
ifneq (${OBJS},)
|
ifneq (${OBJS},)
|
||||||
|
|
||||||
|
|||||||
25
README.md
25
README.md
@ -30,18 +30,6 @@ Uninstall:
|
|||||||
```
|
```
|
||||||
sudo make uni USRDIR=(Your installation dir)
|
sudo make uni USRDIR=(Your installation dir)
|
||||||
```
|
```
|
||||||
For build with with debug flags:
|
|
||||||
```
|
|
||||||
make -j $(nproc) DEBUG=
|
|
||||||
```
|
|
||||||
For build tests (needed gtest package as dependency):
|
|
||||||
```
|
|
||||||
make tests -j $(nproc) DEBUG=
|
|
||||||
```
|
|
||||||
And also flag for dynamic linking (if possible):
|
|
||||||
```
|
|
||||||
make tools -j $(nproc) SHARED=
|
|
||||||
```
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
@ -56,4 +44,17 @@ Now we would like to implement the following features:
|
|||||||
- BCH
|
- BCH
|
||||||
- Bech32
|
- Bech32
|
||||||
|
|
||||||
|
For build with with debug flags:
|
||||||
|
```
|
||||||
|
make -j $(nproc) DEBUG=
|
||||||
|
```
|
||||||
|
For build tests (needed gtest package as dependency):
|
||||||
|
```
|
||||||
|
make tests -j $(nproc) DEBUG=
|
||||||
|
```
|
||||||
|
For generating coverage:
|
||||||
|
```
|
||||||
|
make cover -j $(nproc) DEBUG=
|
||||||
|
```
|
||||||
|
|
||||||
[⬆️ Contents](#contents)
|
[⬆️ Contents](#contents)
|
||||||
|
|||||||
Submodule distrib/arch updated: 0dcfd063ed...3453e4c5cd
@ -74,8 +74,6 @@ namespace base64
|
|||||||
str[i * 4 + 3] = digits[data[i * 3 + 2] & 0x3F];
|
str[i * 4 + 3] = digits[data[i * 3 + 2] & 0x3F];
|
||||||
}
|
}
|
||||||
uint64_t last_idx = data_size / 3 * 4;
|
uint64_t last_idx = data_size / 3 * 4;
|
||||||
if (last_idx + 3 < str_size)
|
|
||||||
{
|
|
||||||
switch (data_size % 3)
|
switch (data_size % 3)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@ -94,7 +92,6 @@ namespace base64
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
std::string encode(std::span<const uint8_t> data) noexcept
|
std::string encode(std::span<const uint8_t> data) noexcept
|
||||||
{
|
{
|
||||||
std::string str(base64::sizeEncoded(data), ' ');
|
std::string str(base64::sizeEncoded(data), ' ');
|
||||||
|
|||||||
29
src/basen.cpp
Normal file
29
src/basen.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <argparse/argparse.hpp>
|
||||||
|
|
||||||
|
#include <basen.hpp>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
argparse::ArgumentParser program("basen", "1.1.0");
|
||||||
|
program.add_argument("-t", "--type")
|
||||||
|
.help("encoding type")
|
||||||
|
.metavar("STRING")
|
||||||
|
.choices("base58", "base64", "hex")
|
||||||
|
.default_value("hex");
|
||||||
|
program.add_argument("-d", "--decode")
|
||||||
|
.help("is decode")
|
||||||
|
.flag();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
program.parse_args(argc, argv);
|
||||||
|
}
|
||||||
|
catch (const std::exception &err)
|
||||||
|
{
|
||||||
|
std::cerr << err.what() << '\n';
|
||||||
|
std::cerr << program;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -28,6 +28,12 @@ TEST(base64, encode)
|
|||||||
{
|
{
|
||||||
for (auto it : tests)
|
for (auto it : tests)
|
||||||
EXPECT_EQ(it.first, encode(hex::decode(it.second)));
|
EXPECT_EQ(it.first, encode(hex::decode(it.second)));
|
||||||
|
|
||||||
|
std::vector<uint8_t> data = {0x74, 0x65, 0x73, 0x74};
|
||||||
|
std::string str = "";
|
||||||
|
EXPECT_THROW(encode(data.data(), std::numeric_limits<uint64_t>::max(), str.data(), str.size()), std::overflow_error);
|
||||||
|
EXPECT_THROW(encode(data.data(), data.size(), str.data(), str.size()), std::length_error);
|
||||||
|
EXPECT_NO_THROW(encode(data.data(), 0, str.data(), str.size()));
|
||||||
}
|
}
|
||||||
TEST(base64, encode_1e7)
|
TEST(base64, encode_1e7)
|
||||||
{
|
{
|
||||||
@ -38,6 +44,12 @@ TEST(base64, decode)
|
|||||||
{
|
{
|
||||||
for (auto it : tests)
|
for (auto it : tests)
|
||||||
EXPECT_EQ(hex::encode(decode(it.first)), it.second);
|
EXPECT_EQ(hex::encode(decode(it.first)), it.second);
|
||||||
|
|
||||||
|
std::vector<uint8_t> data = {0x61, 0x6e, 0x6f};
|
||||||
|
EXPECT_THROW(decode("FFF", 3, data.data(), data.size()), std::logic_error);
|
||||||
|
EXPECT_THROW(decode("!@#!", 4, data.data(), data.size()), std::logic_error);
|
||||||
|
EXPECT_THROW(decode("FF==", 2, data.data(), 0), std::length_error);
|
||||||
|
EXPECT_NO_THROW(decode("" , 0, data.data(), 0));
|
||||||
}
|
}
|
||||||
TEST(base64, decode_1e7)
|
TEST(base64, decode_1e7)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,21 +1,28 @@
|
|||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <basen/hex.hpp>
|
#include <basen/hex.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
using namespace hex;
|
using namespace hex;
|
||||||
|
|
||||||
|
TEST(hex, isValid)
|
||||||
|
{
|
||||||
|
std::vector<std::pair<bool, std::string>> tests = {
|
||||||
|
{true, "1234"},
|
||||||
|
{false, "!@/"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(it.first, isValid(it.second));
|
||||||
|
}
|
||||||
TEST(hex, encode)
|
TEST(hex, encode)
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> data = {0x74, 0x65, 0x73, 0x74};
|
std::vector<uint8_t> data = {0x74, 0x65, 0x73, 0x74};
|
||||||
EXPECT_EQ("74657374", encode(data));
|
EXPECT_EQ("74657374", encode(data));
|
||||||
try
|
|
||||||
{
|
|
||||||
std::string str = "";
|
std::string str = "";
|
||||||
encode(data.data(), data.size(), str.data(), str.size());
|
EXPECT_THROW(encode(data.data(), std::numeric_limits<uint64_t>::max(), str.data(), str.size()), std::overflow_error);
|
||||||
}
|
EXPECT_THROW(encode(data.data(), data.size(), str.data(), str.size()), std::length_error);
|
||||||
catch (const std::exception &e)
|
EXPECT_NO_THROW(encode(data.data(), 0, str.data(), str.size()));
|
||||||
{
|
|
||||||
EXPECT_STREQ(e.what(), "hex::encode: not enough allocated length");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TEST(hex, encode_1e7)
|
TEST(hex, encode_1e7)
|
||||||
{
|
{
|
||||||
@ -26,15 +33,11 @@ TEST(hex, decode)
|
|||||||
{
|
{
|
||||||
std::vector<uint8_t> data = {0x61, 0x6e, 0x6f};
|
std::vector<uint8_t> data = {0x61, 0x6e, 0x6f};
|
||||||
EXPECT_EQ(decode("616e6f"), data);
|
EXPECT_EQ(decode("616e6f"), data);
|
||||||
try
|
|
||||||
{
|
EXPECT_THROW(decode("FFF", 3, data.data(), data.size()), std::logic_error);
|
||||||
std::string str = "";
|
EXPECT_THROW(decode("!@#!", 4, data.data(), data.size()), std::logic_error);
|
||||||
decode("616", 3, data.data(), data.size());
|
EXPECT_THROW(decode("FF", 2, data.data(), 0), std::length_error);
|
||||||
}
|
EXPECT_NO_THROW(decode("", 0, data.data(), 0));
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
EXPECT_STREQ(e.what(), "hex::decode: isn't hex");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TEST(hex, decode_1e7)
|
TEST(hex, decode_1e7)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user