libnmbs 1.0.0
Loading...
Searching...
No Matches
nmbs (Normalised Metadata Binding Service)

nmbs is a lightweight C++ library for generating and parsing NATO confidentiality metadata. It implements core components of the ADatP-4774 and ADatP-4778 specifications, enabling developers to consistently attach standards-compliant labels to files.

Getting Started

If installed via Debian packages (e.g., libnmbs-dev), this documentation is available locally at /usr/share/doc/libnmbs-dev/html/index.html. You can open this directly in a web browser or utilize a package such as dochelp.

The API is rooted in the nmbs namespace and is highly functional. Data structures are kept as simple, immutable structs with minimal internal logic. Most operations are performed via top-level functions (see the nmbs namespace reference).

Integration

Integrate libnmbs1 into your CMake project:

find_package(NMBS REQUIRED CONFIG)
target_link_libraries(Your-Target
PRIVATE
NMBS::NMBS-Library
)

Ensure the core header is included in your source files:

#include <nmbs/nmbs.h>
Main include header for the libnmbs library.

Example Usage

The following minimal example demonstrates writing and reading XMP metadata on an image.

Error handling is managed via nmbs::Expected (an alias for std::expected<T, nmbs::Error>), providing both human-readable messages and programmatic exit codes. Further examples can be found in the targets/NMBS-Examples directory of the source tree.

#include <iostream>
#include <nmbs/nmbs.h>
int main()
{
const std::filesystem::path file{"my-image.jpg"};
std::vector<nmbs::ConfidentialityLabel> labels(1);
labels[0].confidentiality_information.policy_identifier = "PUBLIC";
labels[0].confidentiality_information.classification = "UNMARKED";
if (const auto output = nmbs::write_labels(file, labels); !output.has_value())
{
std::cerr << output.error().message() << std::endl;
return output.error().code();
}
if (const auto result = nmbs::read_binding(file); result && *result)
{
for (const nmbs::binding::BindingInformation& binding = **result; const auto& label : binding.labels)
{
std::cout << label.confidentiality_information.policy_identifier << " " <<
label.confidentiality_information.classification << std::endl;
}
}
else if (!result)
{
std::cerr << result.error().message() << std::endl;
return result.error().code();
}
}
Expected< std::optional< binding::BindingInformation > > read_binding(const std::filesystem::path &path, std::optional< binding::ProfileSupport > binding_support=std::nullopt)
Reads and deserializes the ADatP-4778 binding from the specified file.
@ no_label_present
No label was attached to the file.
Definition exit_code.h:65
@ success
No errors occurred; operation completed successfully.
Definition exit_code.h:37
Expected< std::string > write_labels(const std::filesystem::path &path, const std::vector< ConfidentialityLabel > &confidentiality_labels, std::optional< binding::ProfileSupport > binding_support=std::nullopt)
Writes ADatP-4778 binding information using the optimal binding profile.
Holds information about both the labels, and the file the labels are bound to.
Definition binding_information.h:42
std::vector< ConfidentialityLabel > labels
The collection of confidentiality labels bound to the referenced data.
Definition binding_information.h:69