Enrollment 28.2.0
Loading...
Searching...
No Matches
ANSITemplate.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "enrollment/Export.h"
15
16// cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes: This is not a
17// problem because we are using them only as read only.
18// cppcoreguidelines-avoid-const-or-ref-data-members: We design te API with const member variables instead of
19// implementing getter methods. This is nicely transformed in C# to properties. Usually our objects are immutable by
20// intention to have no problem in multithreaded applications.
21// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes,cppcoreguidelines-avoid-const-or-ref-data-members)
22namespace inno
23{
27 */
28 class ANSITemplate : public Serializable
29 {
30 public:
32 const std::vector<uint8_t> data;
33
37 */
38 explicit ANSITemplate(std::vector<uint8_t>&& d) noexcept
39 : data(std::move(d))
40 {
41 }
42
46 */
47 explicit ANSITemplate(const std::vector<uint8_t>& d)
48 : data(d)
49 {
50 }
51
56 */
57 [[nodiscard]] std::string GetVersion() const
58 {
59 constexpr ptrdiff_t VersionOffset = 4; // defined in "ANSI/NIST-ITL 1-2011 - 8.1.1 Record header"
60 constexpr ptrdiff_t VersionSize = 4; // defined in "ANSI/NIST-ITL 1-2011 - 8.1.2 Version number"
61 if (data.size() < static_cast<std::size_t>(VersionOffset + VersionSize))
62 {
63 throw EnrollmentRuntimeException("Unable to read version from the ANSI template");
64 }
65 const auto* const versionBegin =
66 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
67 std::next(reinterpret_cast<const char*>(data.data()), VersionOffset); // version is stored as ASCII string
68 const auto* const versionEnd = std::next(versionBegin, VersionSize - 1); // last character is null byte
69
70 const int version = std::stoi(std::string{ versionBegin, versionEnd });
71 return std::to_string(version);
72 }
74 void WriteTo(Writer& writer) const final
75 {
76 writer.WriteArray("d", data);
77 }
78
79 ANSITemplate(const ANSITemplate&) = default;
80 ANSITemplate(ANSITemplate&&) = default;
81 ANSITemplate& operator=(const ANSITemplate&) = delete;
82 ANSITemplate& operator=(ANSITemplate&&) = delete;
83 ANSITemplate() = delete;
84 virtual ~ANSITemplate() = default;
85 };
86} // namespace inno
87// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes,cppcoreguidelines-avoid-const-or-ref-data-members)
ANSI INCITS 378 print compliant template.
Definition ANSITemplate.h:28
void WriteTo(Writer &writer) const final
Write itself into writer.
Definition ANSITemplate.h:73
ANSITemplate(std::vector< uint8_t > &&d) noexcept
Create ANSITemplate object.
Definition ANSITemplate.h:37
std::string GetVersion() const
Provides version information of Innovatrics proprietary algorithm used to create the ANSI template.
Definition ANSITemplate.h:56
const std::vector< uint8_t > data
Template data.
Definition ANSITemplate.h:31
ANSITemplate(const std::vector< uint8_t > &d)
Create ANSITemplate object, copy data to ANSI template.
Definition ANSITemplate.h:46
Base exception for all enrollment-sdk runtime exceptions.
Definition EnrollmentException.h:84
Provides interface for serialization of all classes.
Definition Writer.h:164