1 #include "uptane/tuf.h"
8 const std::string Role::ROOT =
"root";
9 const std::string Role::SNAPSHOT =
"snapshot";
10 const std::string Role::TARGETS =
"targets";
11 const std::string Role::TIMESTAMP =
"timestamp";
13 Role::Role(
const std::string &role_name,
const bool delegation) {
14 std::string role_name_lower;
15 std::transform(role_name.begin(), role_name.end(), std::back_inserter(role_name_lower), ::tolower);
16 name_ = role_name_lower;
18 if (IsReserved(name_)) {
19 throw Uptane::Exception(
"",
"Delegated role name " + role_name +
" is reserved.");
21 role_ = RoleEnum::kDelegation;
23 }
else if (role_name_lower == ROOT) {
24 role_ = RoleEnum::kRoot;
25 }
else if (role_name_lower == SNAPSHOT) {
26 role_ = RoleEnum::kSnapshot;
27 }
else if (role_name_lower == TARGETS) {
28 role_ = RoleEnum::kTargets;
29 }
else if (role_name_lower == TIMESTAMP) {
30 role_ = RoleEnum::kTimestamp;
32 role_ = RoleEnum::kInvalidRole;
33 name_ =
"invalidrole";
37 std::string Role::ToString()
const {
return name_; }
39 std::ostream &Uptane::operator<<(std::ostream &os,
const Role &role) {
40 os << role.ToString();
44 std::string Version::RoleFileName(
const Role &role)
const {
46 if (version_ != Version::ANY_VERSION) {
47 ss << version_ <<
".";
49 ss << role.ToString() <<
".json";