Vanetza
 
Loading...
Searching...
No Matches
subject_attribute.hpp
1#ifndef SUBJECT_ATTRIBUTE_HPP_IRZLEB7C
2#define SUBJECT_ATTRIBUTE_HPP_IRZLEB7C
3
4#include <vanetza/security/v2/int_x.hpp>
5#include <vanetza/security/v2/public_key.hpp>
6#include <vanetza/security/v2/serialization.hpp>
7#include <boost/variant/variant.hpp>
8#include <cstdint>
9#include <list>
10
11namespace vanetza
12{
13namespace security
14{
15namespace v2
16{
17
18/// SubjectAssurance specified in TS 103 097 v1.2.1 in section 6.6 and 7.4.1
20{
21 SubjectAssurance(uint8_t _raw = 0) : raw(_raw) {}
22
23 static constexpr uint8_t assurance_mask = 0xE0;
24 static constexpr uint8_t confidence_mask = 0x03;
25
26 uint8_t raw;
27
28 uint8_t assurance() const
29 {
30 return (raw & assurance_mask) >> 5;
31 }
32
33 uint8_t confidence() const
34 {
35 return raw & confidence_mask;
36 }
37};
38
39/// ItsAidSsp specified in TS 103 097 v1.2.1, section 6.9
41{
42 IntX its_aid;
43 ByteBuffer service_specific_permissions;
44};
45
46/// SubjectAttributeType specified in TS 103 097 v1.2.1, section 6.5
47enum class SubjectAttributeType : uint8_t {
48 Verification_Key = 0, //VerificationKey
49 Encryption_Key = 1, //EncryptionKey
50 Assurance_Level = 2, //SubjectAssurance
51 Reconstruction_Value = 3, //EccPoint
52 ITS_AID_List = 32, //std::list<IntX>
53 ITS_AID_SSP_List = 33, //std::list<ItsAidSsp>
54};
55
56/// VerificationKey specified in TS 103 097 v1.2.1, section 6.4
58{
59 PublicKey key;
60};
61
62/// EncryptionKey specified in TS 103 097 v1.2.1, section 6.4
64{
65 PublicKey key;
66};
67
68/// SubjectAttribute specified in TS 103 097 v1.2.1, section 6.4
69using SubjectAttribute = boost::variant<
73 EccPoint,
74 std::list<IntX>,
75 std::list<ItsAidSsp>
76>;
77
78/**
79 * \brief Determines SubjectAttributeType to a given SubjectAttribute
80 * \param attribute
81 * \return type
82 */
83SubjectAttributeType get_type(const SubjectAttribute&);
84
85/**
86 * \brief Calculates size of a SubjectAttribute
87 * \param sub
88 * \return number of octets needed to serialize the SubjectAttribute
89 */
90size_t get_size(const SubjectAttribute&);
91
92/**
93 * \brief Calculates size of a SubjectAssurance
94 * \param sub
95 * \return number of octets needed to serialize the SubjectAssurance
96 */
97size_t get_size(const SubjectAssurance&);
98
99/**
100 * \brief Calculates size of an ItsAidSsp
101 * \param its_aid_ssp
102 * \return number of octets needed to serialize the ItsAidSsp
103 */
104size_t get_size(const ItsAidSsp&);
105
106/**
107 * \brief Deserializes a SubjectAttribute from a binary archive
108 * \param ar with a serialized SubjectAttribute at the beginning
109 * \param sub to deserialize
110 * \return size of the deserialized SubjectAttribute
111 */
112size_t deserialize(InputArchive&, SubjectAttribute&);
113
114/**
115 * \brief Deserializes an ItsAidSsp from a binary archive
116 * \param ar with a serialized ItsAidSsp at the beginning
117 * \param its_aid_ssp to deserialize
118 * \return size of the deserialized ItsAidSsp
119 */
120size_t deserialize(InputArchive&, ItsAidSsp&);
121
122/**
123 * \brief Serializes a SubjectAttribute into a binary archive
124 * \param ar to serialize in
125 * \param sub to serialize
126 */
127void serialize(OutputArchive&, const SubjectAttribute&);
128
129/**
130 * \brief Serializes an ItsAidSsp into a binary archive
131 * \param ar to serialize in
132 * \param its_aid_ssp to serialize
133 */
134void serialize(OutputArchive&, const ItsAidSsp&);
135
136namespace detail
137{
138
139template<SubjectAttributeType>
141
142template<>
143struct subject_attribute_type<SubjectAttributeType::Verification_Key>
144{
145 using type = VerificationKey;
146};
147
148template<>
149struct subject_attribute_type<SubjectAttributeType::Encryption_Key>
150{
151 using type = EncryptionKey;
152};
153
154template<>
155struct subject_attribute_type<SubjectAttributeType::Assurance_Level>
156{
157 using type = SubjectAssurance;
158};
159
160template<>
161struct subject_attribute_type<SubjectAttributeType::Reconstruction_Value>
162{
163 using type = EccPoint;
164};
165
166template<>
167struct subject_attribute_type<SubjectAttributeType::ITS_AID_List>
168{
169 using type = std::list<IntX>;
170};
171
172template<>
173struct subject_attribute_type<SubjectAttributeType::ITS_AID_SSP_List>
174{
175 using type = std::list<ItsAidSsp>;
176};
177
178} // namespace detail
179
180/**
181 * \brief resolve type for matching SubjectAttributeType
182 *
183 * This is kind of the reverse function of get_type(const SubjectAttribute&)
184 */
185template<SubjectAttributeType T>
186using subject_attribute_type = typename detail::subject_attribute_type<T>::type;
187
188} // namespace v2
189} // namespace security
190} // namespace vanetza
191
192#endif /* SUBJECT_ATTRIBUTE_HPP_IRZLEB7C */
IntX specified in TS 103 097 v1.2.1, section 4.2.1.
Definition: int_x.hpp:21
EncryptionKey specified in TS 103 097 v1.2.1, section 6.4.
ItsAidSsp specified in TS 103 097 v1.2.1, section 6.9.
SubjectAssurance specified in TS 103 097 v1.2.1 in section 6.6 and 7.4.1.
VerificationKey specified in TS 103 097 v1.2.1, section 6.4.