Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@

#include "Exports.h"

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

#ifndef LIBCDOC_TESTING
// Remove this in production code
#define LIBCDOC_TESTING 1
#endif

namespace libcdoc {

/**
* @brief A typedef that indicates that integer value may contain libcdoc result code
*/
typedef int64_t result_t;
using result_t = int64_t;

/**
* @brief The public key type
*/
enum class PKType : uint8_t {
/**
* Elliptic curve
*/
ECC,
/**
* RSA
*/
RSA
};

enum {
/**
Expand Down Expand Up @@ -130,10 +139,83 @@ enum {
UNSPECIFIED_ERROR = -199,
};

/**
* @brief Get the standard text description of error code
*
* @param code the error code
* @return the text description
*/
CDOC_EXPORT std::string getErrorStr(int64_t code);

/**
* @brief Get the library version
*
* @return The version string
*/
CDOC_EXPORT std::string getVersion();

// Logging interface

/**
* @brief Log-level enumeration to indicate severity of the log message.
*/
enum LogLevel : uint8_t
{
/**
* @brief Most critical level. Application is about to abort.
*/
LEVEL_FATAL,

/**
* @brief Errors where functionality has failed or an exception have been caught.
*/
LEVEL_ERROR,

/**
* @brief Warnings about validation issues or temporary failures that can be recovered.
*/
LEVEL_WARNING,

/**
* @brief Information that highlights progress or application lifetime events.
*/
LEVEL_INFO,

/**
* @brief Debugging the application behavior from internal events of interest.
*/
LEVEL_DEBUG,

/**
* @brief The most verbose level. Present only in development builds, ignored in production code.
*/
LEVEL_TRACE
};

class Logger;

/**
* @brief Set the Logger object for library
*
* @param logger the Logger implementation
*/
CDOC_EXPORT void setLogger(Logger *logger);
/**
* @brief Set logging level
*
* @param level the requested logging level
*/
CDOC_EXPORT void setLogLevel(LogLevel level);
/**
* @brief Log a message to the library logging system
*
* @param level logging level
* @param file the source file name
* @param line the line in source file
* @param msg the message
*/
CDOC_EXPORT void log(LogLevel level, std::string_view file, int line, std::string_view msg);

/**
* @brief A simple container of file name and size
*
Expand All @@ -144,6 +226,38 @@ struct FileInfo {
int64_t size;
};

namespace CDoc2 {
namespace Label {
/**
* @brief Recipient types for machine-readable labels
*
*/
static constexpr std::string_view TYPE_PASSWORD = "pw";
static constexpr std::string_view TYPE_SYMMETRIC = "secret";
static constexpr std::string_view TYPE_PUBLIC_KEY = "pub_key";
static constexpr std::string_view TYPE_CERTIFICATE = "cert";
static constexpr std::string_view TYPE_UNKNOWN = "Unknown";
static constexpr std::string_view TYPE_ID_CARD = "ID-card";
static constexpr std::string_view TYPE_DIGI_ID = "Digi-ID";
static constexpr std::string_view TYPE_DIGI_ID_E_RESIDENT = "Digi-ID E-RESIDENT";

/**
* @brief Recipient data for machine-readable labels
*
*/
static constexpr std::string_view VERSION = "v";
static constexpr std::string_view TYPE = "type";
static constexpr std::string_view FILE = "file";
static constexpr std::string_view LABEL = "label";
static constexpr std::string_view CN = "cn";
static constexpr std::string_view SERIAL_NUMBER = "serial_number";
static constexpr std::string_view LAST_NAME = "last_name";
static constexpr std::string_view FIRST_NAME = "first_name";
static constexpr std::string_view CERT_SHA1 = "cert_sha1";
static constexpr const char* EXPIRY = "server_exp";
}
}

}; // namespace libcdoc

#endif // CDOC_H
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "CDoc.h"

#include <cstdint>
#include <vector>

namespace libcdoc {

Expand All @@ -39,7 +39,7 @@ struct NetworkBackend;
*/
class CDOC_EXPORT CDocReader {
public:
virtual ~CDocReader() = default;
virtual ~CDocReader() noexcept = default;

/**
* @brief The container version (1 or 2)
Expand Down Expand Up @@ -200,10 +200,6 @@ class CDOC_EXPORT CDocReader {
*/
static CDocReader *createReader(std::istream& ifs, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network);

#if LIBCDOC_TESTING
virtual int64_t testConfig(std::vector<uint8_t>& dst);
virtual int64_t testNetwork(std::vector<std::vector<uint8_t>>& dst);
#endif
protected:
explicit CDocReader(int _version) : version(_version) {};

Expand All @@ -214,6 +210,9 @@ class CDOC_EXPORT CDocReader {
Configuration *conf = nullptr;
CryptoBackend *crypto = nullptr;
NetworkBackend *network = nullptr;

private:
CDOC_DISABLE_MOVE_COPY(CDocReader);
};

} // namespace libcdoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "CDoc.h"

#include <cstdint>
#include <vector>

namespace libcdoc {
struct Configuration;
Expand All @@ -38,7 +38,7 @@ namespace libcdoc {
*/
class CDOC_EXPORT CDocWriter {
public:
virtual ~CDocWriter();
virtual ~CDocWriter() noexcept;

/**
* @brief The container version (1 or 2)
Expand Down Expand Up @@ -154,6 +154,7 @@ class CDOC_EXPORT CDocWriter {
static CDocWriter *createWriter(int version, const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network);
protected:
explicit CDocWriter(int _version, DataConsumer *dst, bool take_ownership);
CDOC_DISABLE_MOVE_COPY(CDocWriter);

void setLastError(const std::string& message) { last_error = message; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct CDOC_EXPORT Configuration {
* @brief Fetch URL of keyserver (Domain is server id)
*/
static constexpr char const *KEYSERVER_FETCH_URL = "KEYSERVER_FETCH_URL";
#ifdef HAS_KEYSHARES
/**
* @brief JSON array of share server base urls (Domain is server id)
*/
Expand Down Expand Up @@ -74,6 +75,7 @@ struct CDOC_EXPORT Configuration {
* @brief Mobile ID phone number (domain is MOBILE_ID)
*/
static constexpr char const *PHONE_NUMBER = "PHONE_NUMBER";
#endif

Configuration() = default;
virtual ~Configuration() noexcept = default;
Expand All @@ -92,36 +94,32 @@ struct CDOC_EXPORT Configuration {
virtual std::string getValue(std::string_view domain, std::string_view param) const {return {};}

/**
* @brief get a value of configuration parameter from default domain
* @brief get a value of configuration parameter from the default domain
* @param param the parameter name.
* @return a string value or empty string if parameter is not defined.
*/
std::string getValue(std::string_view param) const {return getValue({}, param);}
/**
* @brief get boolean value of configuration parameter from default domain
* @brief get boolean value of configuration parameter from the default domain
* @param param the parameter name
* @param def_val the default value to return if parameter is not set
* @return the parameter value
*/
bool getBoolean(std::string_view param, bool def_val = false) const;
/**
* @brief get integer value of configuration parameter from default domain
* @brief get integer value of configuration parameter from the default domain
* @param param the parameter name
* @param def_val the default value to return if parameter is not set
* @return the key value
*/
int getInt(std::string_view param, int def_val = 0) const;

#if LIBCDOC_TESTING
virtual int64_t test(std::vector<uint8_t>& dst) { return OK; }
#endif
};

/**
* @brief A Configuration object implementation that reads values from JSON file
*
* The file should represent a single object with key/value pairs
* Domain should contain sub-objects with corresponding key/value pairs
* Domains are sub-objects with corresponding key/value pairs
* Strings are returned unquoted, everything else is returned as JSON
*
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <cdoc/CDoc.h>

#include <cstdint>
#include <vector>

namespace libcdoc {

Expand Down
Loading
Loading