Repository navigation
Expand file tree
/
Copy pathfix_evidence.cpp
More file actions
66 lines (61 loc) · 2.18 KB
/
Copy pathfix_evidence.cpp
File metadata and controls
66 lines (61 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <teaql/runtime/fix_evidence.hpp>
#include <teaql/core/detail/text.hpp>
#include <array>
namespace teaql {
namespace {
bool contains_ascii_folded(std::string_view text, std::string_view word) {
if (text.size() < word.size()) {
return false;
}
for (std::size_t start = 0; start <= text.size() - word.size(); ++start) {
bool match = true;
for (std::size_t i = 0; i < word.size(); ++i) {
auto c = text[start + i];
if (c >= 'A' && c <= 'Z') {
c += 'a' - 'A';
}
if (c != word[i]) {
match = false;
break;
}
}
if (match) {
return true;
}
}
return false;
}
void nonblank(std::string_view value, const char* message) {
detail::trim(value);
if (value.empty()) {
throw std::invalid_argument(message);
}
}
}
std::string_view fix_evidence_source_name(FixEvidenceSource source) {
constexpr std::array<std::string_view, 2> names{"Clock", "Context"};
return names.at(std::size_t(source));
}
FixEvidence::FixEvidence(std::allocator_arg_t,
Allocator a,
std::string_view entity,
std::string_view path,
FixEvidenceSource source,
std::string_view label)
: entity_type(a.resource()), model_path(a.resource()), source(source),
source_label(a.resource()) {
nonblank(entity, "entity_type must not be blank");
nonblank(path, "model_path must not be blank");
nonblank(label, "source_label must not be blank");
if (contains_ascii_folded(label, "authorization") || contains_ascii_folded(label, "cookie") ||
contains_ascii_folded(label, "token=")) {
throw std::invalid_argument("source_label must be a safe framework label");
}
entity_type = entity;
model_path = path;
source_label = label;
}
FixEvidence::FixEvidence(std::allocator_arg_t, Allocator a, const FixEvidence& other)
: entity_type(other.entity_type, a.resource()), model_path(other.model_path, a.resource()),
source(other.source), source_label(other.source_label, a.resource()) {}
}