Skip to content

Commit 8996205

Browse files
authored
[k2] move tl magic and mask types out of details namespace (#1341)
1 parent 6362473 commit 8996205

5 files changed

Lines changed: 61 additions & 65 deletions

File tree

runtime-light/stdlib/crypto/crypto-functions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ kphp::coro::task<Optional<string>> f$openssl_random_pseudo_bytes(int64_t length)
5050
tlb.store_bytes({response.c_str(), static_cast<size_t>(response.size())});
5151

5252
// Maybe better to do this in some structure, but there's not much work to do with TL here
53-
if (tl::details::magic magic{}; !magic.fetch(tlb) || !magic.expect(TL_MAYBE_TRUE)) {
53+
if (tl::magic magic{}; !magic.fetch(tlb) || !magic.expect(TL_MAYBE_TRUE)) {
5454
co_return false;
5555
}
5656

@@ -120,7 +120,7 @@ kphp::coro::task<bool> f$openssl_sign(string data, string& signature, string pri
120120
tlb.clean();
121121
tlb.store_bytes({response.c_str(), static_cast<size_t>(response.size())});
122122

123-
if (tl::details::magic magic{}; !magic.fetch(tlb) || !magic.expect(TL_MAYBE_TRUE)) {
123+
if (tl::magic magic{}; !magic.fetch(tlb) || !magic.expect(TL_MAYBE_TRUE)) {
124124
co_return false;
125125
}
126126

@@ -150,7 +150,7 @@ kphp::coro::task<int64_t> f$openssl_verify(string data, string signature, string
150150

151151
// For now returns only 1 or 0, -1 is never returned
152152
// Because it's currently impossible to distiguish error from negative verification
153-
if (tl::details::magic magic{}; !magic.fetch(tlb) || !magic.expect(TL_BOOL_TRUE)) {
153+
if (tl::magic magic{}; !magic.fetch(tlb) || !magic.expect(TL_BOOL_TRUE)) {
154154
co_return 0;
155155
}
156156
co_return 1;

runtime-light/tl/tl-functions.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace tl {
1515
// ===== JOB WORKERS =====
1616

1717
bool K2InvokeJobWorker::fetch(tl::TLBuffer& tlb) noexcept {
18-
tl::details::magic magic{};
19-
tl::details::mask flags{};
18+
tl::magic magic{};
19+
tl::mask flags{};
2020
bool ok{magic.fetch(tlb) && magic.expect(K2_INVOKE_JOB_WORKER_MAGIC)};
2121
ok &= flags.fetch(tlb);
2222
ok &= image_id.fetch(tlb);
@@ -28,8 +28,8 @@ bool K2InvokeJobWorker::fetch(tl::TLBuffer& tlb) noexcept {
2828
}
2929

3030
void K2InvokeJobWorker::store(tl::TLBuffer& tlb) const noexcept {
31-
tl::details::magic{.value = K2_INVOKE_JOB_WORKER_MAGIC}.store(tlb);
32-
tl::details::mask{.value = ignore_answer ? IGNORE_ANSWER_FLAG : 0x0}.store(tlb);
31+
tl::magic{.value = K2_INVOKE_JOB_WORKER_MAGIC}.store(tlb);
32+
tl::mask{.value = ignore_answer ? IGNORE_ANSWER_FLAG : 0x0}.store(tlb);
3333
image_id.store(tlb);
3434
job_id.store(tlb);
3535
timeout_ns.store(tlb);
@@ -39,33 +39,33 @@ void K2InvokeJobWorker::store(tl::TLBuffer& tlb) const noexcept {
3939
// ===== CRYPTO =====
4040

4141
void GetCryptosecurePseudorandomBytes::store(tl::TLBuffer& tlb) const noexcept {
42-
tl::details::magic{.value = GET_CRYPTOSECURE_PSEUDORANDOM_BYTES_MAGIC}.store(tlb);
42+
tl::magic{.value = GET_CRYPTOSECURE_PSEUDORANDOM_BYTES_MAGIC}.store(tlb);
4343
size.store(tlb);
4444
}
4545

4646
void GetPemCertInfo::store(tl::TLBuffer& tlb) const noexcept {
47-
tl::details::magic{.value = GET_PEM_CERT_INFO_MAGIC}.store(tlb);
47+
tl::magic{.value = GET_PEM_CERT_INFO_MAGIC}.store(tlb);
4848
tl::Bool{.value = is_short}.store(tlb);
4949
bytes.store(tlb);
5050
}
5151

5252
void DigestSign::store(tl::TLBuffer& tlb) const noexcept {
53-
tl::details::magic{.value = DIGEST_SIGN_MAGIC}.store(tlb);
53+
tl::magic{.value = DIGEST_SIGN_MAGIC}.store(tlb);
5454
data.store(tlb);
5555
private_key.store(tlb);
5656
tlb.store_trivial<uint32_t>(algorithm);
5757
}
5858

5959
void DigestVerify::store(tl::TLBuffer& tlb) const noexcept {
60-
tl::details::magic{.value = DIGEST_VERIFY_MAGIC}.store(tlb);
60+
tl::magic{.value = DIGEST_VERIFY_MAGIC}.store(tlb);
6161
data.store(tlb);
6262
public_key.store(tlb);
6363
tlb.store_trivial<uint32_t>(algorithm);
6464
signature.store(tlb);
6565
}
6666

6767
void CbcDecrypt::store(tl::TLBuffer& tlb) const noexcept {
68-
tl::details::magic{.value = CBC_DECRYPT_MAGIC}.store(tlb);
68+
tl::magic{.value = CBC_DECRYPT_MAGIC}.store(tlb);
6969
tlb.store_trivial<uint32_t>(algorithm);
7070
tlb.store_trivial<uint32_t>(padding);
7171
passphrase.store(tlb);
@@ -74,7 +74,7 @@ void CbcDecrypt::store(tl::TLBuffer& tlb) const noexcept {
7474
}
7575

7676
void CbcEncrypt::store(tl::TLBuffer& tlb) const noexcept {
77-
tl::details::magic{.value = CBC_ENCRYPT_MAGIC}.store(tlb);
77+
tl::magic{.value = CBC_ENCRYPT_MAGIC}.store(tlb);
7878
tlb.store_trivial<uint32_t>(algorithm);
7979
tlb.store_trivial<uint32_t>(padding);
8080
passphrase.store(tlb);
@@ -83,13 +83,13 @@ void CbcEncrypt::store(tl::TLBuffer& tlb) const noexcept {
8383
}
8484

8585
void Hash::store(tl::TLBuffer& tlb) const noexcept {
86-
tl::details::magic{.value = HASH_MAGIC}.store(tlb);
86+
tl::magic{.value = HASH_MAGIC}.store(tlb);
8787
tlb.store_trivial<uint32_t>(algorithm);
8888
data.store(tlb);
8989
}
9090

9191
void HashHmac::store(tl::TLBuffer& tlb) const noexcept {
92-
tl::details::magic{.value = HASH_HMAC_MAGIC}.store(tlb);
92+
tl::magic{.value = HASH_HMAC_MAGIC}.store(tlb);
9393
tlb.store_trivial<uint32_t>(algorithm);
9494
data.store(tlb);
9595
secret_key.store(tlb);
@@ -98,20 +98,20 @@ void HashHmac::store(tl::TLBuffer& tlb) const noexcept {
9898
// ===== CONFDATA =====
9999

100100
void ConfdataGet::store(tl::TLBuffer& tlb) const noexcept {
101-
tl::details::magic{.value = CONFDATA_GET_MAGIC}.store(tlb);
101+
tl::magic{.value = CONFDATA_GET_MAGIC}.store(tlb);
102102
key.store(tlb);
103103
}
104104

105105
void ConfdataGetWildcard::store(tl::TLBuffer& tlb) const noexcept {
106-
tl::details::magic{.value = CONFDATA_GET_WILDCARD_MAGIC}.store(tlb);
106+
tl::magic{.value = CONFDATA_GET_WILDCARD_MAGIC}.store(tlb);
107107
wildcard.store(tlb);
108108
}
109109

110110
// ===== HTTP =====
111111

112112
bool K2InvokeHttp::fetch(tl::TLBuffer& tlb) noexcept {
113-
tl::details::magic magic{};
114-
tl::details::mask flags{};
113+
tl::magic magic{};
114+
tl::mask flags{};
115115
bool ok{magic.fetch(tlb) && magic.expect(K2_INVOKE_HTTP_MAGIC)};
116116
ok &= flags.fetch(tlb);
117117
ok &= connection.fetch(tlb);

runtime-light/tl/tl-functions.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ class K2InvokeRpc final {
154154
static constexpr auto EXTRA_FLAG = static_cast<uint32_t>(1U << 1U);
155155

156156
public:
157-
tl::details::mask flags{};
157+
tl::mask flags{};
158158
tl::i64 query_id{};
159159
tl::netPid net_pid{};
160160
std::optional<tl::i64> opt_actor_id;
161161
std::optional<tl::rpcInvokeReqExtra> opt_extra;
162162
std::string_view query;
163163

164164
bool fetch(tl::TLBuffer& tlb) noexcept {
165-
tl::details::magic magic{};
165+
tl::magic magic{};
166166
bool ok{magic.fetch(tlb) && magic.expect(K2_INVOKE_RPC_MAGIC)};
167167
ok &= flags.fetch(tlb);
168168
ok &= query_id.fetch(tlb);
@@ -192,7 +192,7 @@ struct CacheStore final {
192192
tl::u32 ttl;
193193

194194
void store(TLBuffer& tlb) const noexcept {
195-
tl::details::magic{.value = CACHE_STORE_MAGIC}.store(tlb);
195+
tl::magic{.value = CACHE_STORE_MAGIC}.store(tlb);
196196
key.store(tlb);
197197
value.store(tlb);
198198
ttl.store(tlb);
@@ -204,7 +204,7 @@ struct CacheUpdateTtl final {
204204
tl::u32 ttl;
205205

206206
void store(TLBuffer& tlb) const noexcept {
207-
tl::details::magic{.value = CACHE_UPDATE_TTL_MAGIC}.store(tlb);
207+
tl::magic{.value = CACHE_UPDATE_TTL_MAGIC}.store(tlb);
208208
key.store(tlb);
209209
ttl.store(tlb);
210210
}
@@ -214,7 +214,7 @@ struct CacheDelete final {
214214
tl::string key;
215215

216216
void store(TLBuffer& tlb) const noexcept {
217-
tl::details::magic{.value = CACHE_DELETE_MAGIC}.store(tlb);
217+
tl::magic{.value = CACHE_DELETE_MAGIC}.store(tlb);
218218
key.store(tlb);
219219
}
220220
};
@@ -223,7 +223,7 @@ struct CacheFetch final {
223223
tl::string key;
224224

225225
void store(TLBuffer& tlb) const noexcept {
226-
tl::details::magic{.value = CACHE_FETCH_MAGIC}.store(tlb);
226+
tl::magic{.value = CACHE_FETCH_MAGIC}.store(tlb);
227227
key.store(tlb);
228228
}
229229
};

runtime-light/tl/tl-types.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,23 @@ void string::store(TLBuffer& tlb) const noexcept {
104104
}
105105

106106
bool K2JobWorkerResponse::fetch(TLBuffer& tlb) noexcept {
107-
tl::details::magic magic{};
107+
tl::magic magic{};
108108
bool ok{magic.fetch(tlb) && magic.expect(MAGIC)};
109-
ok &= tl::details::mask{}.fetch(tlb);
109+
ok &= tl::mask{}.fetch(tlb);
110110
ok &= job_id.fetch(tlb);
111111
ok &= body.fetch(tlb);
112112
return ok;
113113
}
114114

115115
void K2JobWorkerResponse::store(TLBuffer& tlb) const noexcept {
116-
tl::details::magic{.value = MAGIC}.store(tlb);
117-
tl::details::mask{}.store(tlb);
116+
tl::magic{.value = MAGIC}.store(tlb);
117+
tl::mask{}.store(tlb);
118118
job_id.store(tlb);
119119
body.store(tlb);
120120
}
121121

122122
bool CertInfoItem::fetch(TLBuffer& tlb) noexcept {
123-
tl::details::magic magic{};
123+
tl::magic magic{};
124124
if (!magic.fetch(tlb)) [[unlikely]] {
125125
return false;
126126
}

0 commit comments

Comments
 (0)