Files
GCrypt/GCryptLib/include/GCrypt/Util.h
T

66 lines
2.2 KiB
C++
Raw Normal View History

#ifndef GCRYPT_UTIL_H
#define GCRYPT_UTIL_H
#include <bitset>
#include <sstream>
#include <fstream>
#include <cstring>
2022-05-16 22:35:28 +02:00
#include "GCrypt/Block.h"
#include "GCrypt/Flexblock.h"
#include "GCrypt/Config.h"
2022-05-22 12:51:58 +02:00
#include "GCrypt/GCipher.h"
2022-05-16 22:35:28 +02:00
#include "GCrypt/InitializationVector.h"
namespace Leonetienne::GCrypt {
2022-05-22 17:32:54 +02:00
//! Mod-operator that works with negative values
inline int Mod(const int numerator, const int denominator) {
return (denominator + (numerator % denominator)) % denominator;
}
2022-05-22 17:32:54 +02:00
//! Will pad a string to a set length with a certain character
std::string PadStringToLength(const std::string& str, const std::size_t len, const char pad, const bool padLeft = true);
2022-05-22 17:32:54 +02:00
//! Will convert a string to a fixed-size data block
//! @s: The string to pad
//! padLeft: should padding be added to the left? If not, to the right.
Block StringToBitblock(const std::string& s, bool padLeft = true);
2022-05-22 17:32:54 +02:00
//! Will convert a string to a flexible data block
Flexblock StringToBits(const std::string& s);
2022-05-22 17:32:54 +02:00
//! Will convert a fixed-size data block to a bytestring
std::string BitblockToBytes(const Block& bits);
2022-05-16 22:01:52 +02:00
2022-05-22 17:32:54 +02:00
//! Will convert a fixed-size data block to a string
//! The difference to BitblockToBytes() is, that it strips excess nullbytes
std::string BitblockToString(const Block& bits);
2022-05-22 17:32:54 +02:00
//! Will convert a flexible data block to a bytestring
std::string BitsToBytes(const Flexblock& bits);
2022-05-22 17:32:54 +02:00
//! Will convert a flexible data block to a string
//! The difference to BitsToBytes() is, that it strips excess nullbytes
std::string BitsToString(const Flexblock& bits);
2022-05-22 17:32:54 +02:00
//! Turns a fixed-size data block into a hex-string
std::string BitblockToHexstring(const Block& b);
2022-05-22 17:32:54 +02:00
//! Turns a flexible data block into a hex-string
std::string BitsToHexstring(const Flexblock& b);
2022-05-22 17:32:54 +02:00
//! Turns a hex string into a fixed-size data block
Block HexstringToBitblock(const std::string& hexstring);
2022-05-22 17:32:54 +02:00
//! Turns a hex string into a flexible data block
Flexblock HexstringToBits(const std::string& hexstring);
2022-05-22 17:32:54 +02:00
//! Will read a file into a flexblock
Flexblock ReadFileToBits(const std::string& filepath);
2022-05-22 17:32:54 +02:00
//! Will save bits to a binary file
void WriteBitsToFile(const std::string& filepath, const Flexblock& bits);
}
2022-05-16 22:01:52 +02:00
#endif