trust-store 2.0.3
Provides a common implementation of a trust store to be used by trusted helpers.
tagged_integer.h
Go to the documentation of this file.
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18
19#ifndef CORE_TRUST_TAGGED_INTEGER_H_
20#define CORE_TRUST_TAGGED_INTEGER_H_
21
22#include <cstdint>
23
24#include <ostream>
25#include <type_traits>
26
27#include <sys/types.h>
28
29namespace core
30{
31namespace trust
32{
34template<typename Tag, typename Integer>
36{
38 static_assert(std::is_integral<Integer>::value, "Integer has to be an integral type");
39
41 typedef Tag TagType;
43 typedef Integer IntegerType;
44
47 {
48 }
49
51 explicit TaggedInteger(Integer value) : value{value}
52 {
53 }
54
56 Integer value;
57};
58
60template<typename Tag, typename Integer>
62{
63 return lhs.value == rhs.value;
64}
65
67template<typename Tag, typename Integer>
69{
70 return lhs.value != rhs.value;
71}
72
74template<typename Tag, typename Integer>
76{
77 return lhs.value < rhs.value;
78}
79
81template<typename Tag, typename Integer>
82inline std::ostream& operator<<(std::ostream& out, const TaggedInteger<Tag, Integer>& ti)
83{
84 return out << ti.value;
85}
86
87namespace tag
88{
89// Tags a group id
90struct Gid {};
91// Tags a process id
92struct Pid {};
93// Tags a user id
94struct Uid {};
95// Tags a service-specific feature
96struct Feature {};
97}
98
107}
108}
109
110#endif // CORE_TRUST_TAGGED_INTEGER_H_
Contains functionality for implementing Ubuntu's trust model.
Definition agent.h:31
CORE_TRUST_DLL_PUBLIC std::ostream & operator<<(std::ostream &out, const Request::Answer &a)
operator << pretty prints answers to the provided output stream.
bool operator<(const TaggedInteger< Tag, Integer > &lhs, const TaggedInteger< Tag, Integer > &rhs)
Returns true iff the left-hand-side integer instance is smaller than the right-hand-side.
TaggedInteger< tag::Feature, std::uint64_t > Feature
Our internal service-feature type.
TaggedInteger< tag::Uid, uid_t > Uid
Our internal user id type.
TaggedInteger< tag::Pid, pid_t > Pid
Our internal process id type.
CORE_TRUST_DLL_PUBLIC bool operator==(const Agent::RequestParameters &lhs, const Agent::RequestParameters &rhs)
Returns true iff lhs and rhs are equal.
bool operator!=(const TaggedInteger< Tag, Integer > &lhs, const TaggedInteger< Tag, Integer > &rhs)
Returns true iff both tagged integer instances are not equal.
TaggedInteger< tag::Gid, gid_t > Gid
Our internal group id type.
Definition agent.h:29
Helper structure for tagging integer types with certain semantics.
Tag TagType
We bail out if the Integral type is not an integral one.
Integer IntegerType
Stores the Integer type.
TaggedInteger(Integer value)
Construct an instance from an existing integer type.
TaggedInteger()
Construct an instance with a default value.