Vanetza
Loading...
Searching...
No Matches
trailer_field.hpp
1#ifndef TRAILER_FIELD_HPP_3PDKGWCQ
2#define TRAILER_FIELD_HPP_3PDKGWCQ
3
4#include <vanetza/common/byte_buffer.hpp>
5#include <vanetza/security/v2/signature.hpp>
6#include <boost/variant/variant.hpp>
7#include <cstdint>
8
9namespace vanetza
10{
11namespace security
12{
13namespace v2
14{
15
16/// TrailerFieldType specified in TS 103 097 v1.2.1, section 5.7
17enum class TrailerFieldType : uint8_t
18{
19 Signature = 1
20};
21
22/// TrailerField specified in TS 103 097 v1.2.1, section 5.6
23using TrailerField = boost::variant<Signature>;
24
25/**
26 * \brief Determines TrailerFieldType to a given TrailerField
27 * \param field
28 * \return type
29 */
30TrailerFieldType get_type(const TrailerField&);
31
32/**
33 * \brief Calculates size of a TrailerField
34 * \param field
35 * \return number of octets needed to serialize the TrailerField
36 */
37size_t get_size(const TrailerField&);
38
39/**
40 * \brief Serializes a TrailerField into a binary archive
41 * \param ar to serialize in
42 * \param field to serialize
43 */
44void serialize(OutputArchive&, const TrailerField&);
45
46/**
47 * \brief Deserializes a TrailerField from a binary archive
48 * \param ar with a serialized TrailerField at the beginning
49 * \param field to deserialize
50 * \return size of the deserialized TrailerField
51 */
52size_t deserialize(InputArchive&, TrailerField&);
53
54/**
55 * \brief Extract binary signature from trailer field
56 *
57 * Serializes signature's s and ECC point x elements.
58 *
59 * \param trailer_field field to be converted
60 * \return ByteBuffer if trailer field contains a signature
61 */
62boost::optional<ByteBuffer> extract_signature_buffer(const TrailerField& trailer_field);
63
64/**
65 * \brief resolve type for matching TrailerFieldType
66 *
67 * This is kind of the reverse function of get_type(const TrailerField&)
68 */
69template<TrailerFieldType>
71
72template<>
73struct trailer_field_type<TrailerFieldType::Signature> { using type = Signature; };
74
75} // namespace v2
76} // namespace security
77} // namespace vanetza
78
79#endif /* TRAILER_FIELD_HPP_3PDKGWCQ */
resolve type for matching TrailerFieldType