AusweisApp
Lade ...
Suche ...
Keine Treffer
LengthValue.h
gehe zur Dokumentation dieser Datei
1
9#pragma once
10
11#include <QByteArray>
12#include <QtEndian>
13
14#include <algorithm>
15#include <climits>
16
17
18namespace governikus
19{
20
22{
23 private:
24 LengthValue() = delete;
25 ~LengthValue() = delete;
26
27 public:
28 template<typename T> static QByteArray readByteArray(const QByteArray& pInput, int& pOffset)
29 {
30 Q_ASSERT(sizeof(T) < INT_MAX);
31
32 const auto typeLength = static_cast<int>(sizeof(T));
33 if (pInput.size() < pOffset + typeLength)
34 {
35 return QByteArray();
36 }
37
38 const T length = qFromLittleEndian<T>(pInput.data() + pOffset);
40 const QByteArray result = pInput.mid(pOffset, length);
41 pOffset += length;
42 return result;
43 }
44
45
46 template<typename T> static void writeByteArray(const QByteArray& pValue, QByteArray& pOutput)
47 {
48 Q_ASSERT(sizeof(T) < INT_MAX);
49
50 const int maxSize = std::numeric_limits<T>::max();
51 const int size = std::min(maxSize, static_cast<int>(pValue.size()));
52
53 const auto it = pOutput.size();
54 pOutput.resize(it + static_cast<int>(sizeof(T)));
55 qToLittleEndian(static_cast<T>(size), pOutput.data() + it);
56 pOutput += pValue.mid(0, size);
57 }
58
59
60};
61
62} // namespace governikus
Definition LengthValue.h:22
static QByteArray readByteArray(const QByteArray &pInput, int &pOffset)
Definition LengthValue.h:28
static void writeByteArray(const QByteArray &pValue, QByteArray &pOutput)
Definition LengthValue.h:46
#define T(v)
Definition http_parser.cpp:237
Implementation of GeneralAuthenticate response APDUs.
Definition CommandApdu.h:17
QSharedPointer< T > decodeObject(const QByteArray &pData, bool pLogging=true)
Template function for decoding an OpenSSL type from DER encoded QByteArray.
Definition ASN1TemplateUtil.h:114