Skip to content

Commit 6126b35

Browse files
Copilotbbockelm
andcommitted
Apply clang-format to fix linter issues
Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
1 parent 98036ed commit 6126b35

File tree

5 files changed

+140
-128
lines changed

5 files changed

+140
-128
lines changed

src/scitokens.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ int scitoken_get_expiration(const SciToken token, long long *expiry,
246246
// Float value - convert to integer (truncate)
247247
// Float value - convert to integer using std::floor().
248248
// This ensures expiration is not extended by fractional seconds.
249-
result = static_cast<long long>(std::floor(claim_value.get<double>()));
249+
result =
250+
static_cast<long long>(std::floor(claim_value.get<double>()));
250251
} else {
251252
if (err_msg) {
252-
*err_msg = strdup("'exp' claim must be a number (integer or float)");
253+
*err_msg =
254+
strdup("'exp' claim must be a number (integer or float)");
253255
}
254256
return -1;
255257
}
@@ -1080,9 +1082,9 @@ int scitoken_config_set_str(const char *key, const char *value,
10801082
return -1;
10811083
}
10821084
} else if (_key == "tls.ca_file") {
1083-
configurer::Configuration::set_tls_ca_file(value ? std::string(value) : "");
1084-
}
1085-
else {
1085+
configurer::Configuration::set_tls_ca_file(value ? std::string(value)
1086+
: "");
1087+
} else {
10861088
if (err_msg) {
10871089
*err_msg = strdup("Key not recognized.");
10881090
}

src/scitokens.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ int scitoken_config_get_str(const char *key, char **output, char **err_msg);
336336
* - unsuccessful_validations: count of failed token validations
337337
* - expired_tokens: count of expired tokens encountered
338338
* - total_validation_time_s: total validation time in seconds
339-
* - failed_issuer_lookups: count of failed issuer lookups (limited to prevent DDoS)
339+
* - failed_issuer_lookups: count of failed issuer lookups (limited to prevent
340+
* DDoS)
340341
*
341342
* The returned string must be freed by the caller using free().
342343
* Returns 0 on success, nonzero on failure.

src/scitokens_internal.cpp

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -684,94 +684,97 @@ std::unique_ptr<AsyncStatus> Validator::get_public_keys_from_web_continue(
684684
if (!cget_status.m_done) {
685685
return std::move(status);
686686
}
687-
if (cget_status.m_status_code != 200) {
688-
if (status->m_oauth_fallback) {
689-
throw IssuerLookupException("Failed to retrieve metadata provider "
690-
"information for issuer.");
691-
} else {
692-
status->m_oauth_fallback = true;
693-
status->m_cget.reset(new internal::SimpleCurlGet());
694-
cget_status =
695-
status->m_cget->perform_start(status->m_oauth_metadata_url);
696-
if (!cget_status.m_done) {
697-
return std::move(status);
687+
if (cget_status.m_status_code != 200) {
688+
if (status->m_oauth_fallback) {
689+
throw IssuerLookupException(
690+
"Failed to retrieve metadata provider "
691+
"information for issuer.");
692+
} else {
693+
status->m_oauth_fallback = true;
694+
status->m_cget.reset(new internal::SimpleCurlGet());
695+
cget_status = status->m_cget->perform_start(
696+
status->m_oauth_metadata_url);
697+
if (!cget_status.m_done) {
698+
return std::move(status);
699+
}
700+
return get_public_keys_from_web_continue(std::move(status));
698701
}
699-
return get_public_keys_from_web_continue(std::move(status));
700702
}
703+
status->m_cget->get_data(buffer, len);
704+
std::string metadata(buffer, len);
705+
picojson::value json_obj;
706+
auto err = picojson::parse(json_obj, metadata);
707+
if (!err.empty()) {
708+
throw JsonException("JSON parse failure when downloading from "
709+
"the metadata URL " +
710+
status->m_cget->get_url() + ": " + err);
711+
}
712+
if (!json_obj.is<picojson::object>()) {
713+
throw JsonException("Metadata resource " +
714+
status->m_cget->get_url() +
715+
" contains "
716+
"improperly-formatted JSON.");
717+
}
718+
auto top_obj = json_obj.get<picojson::object>();
719+
auto iter = top_obj.find("jwks_uri");
720+
if (iter == top_obj.end() || (!iter->second.is<std::string>())) {
721+
throw JsonException("Metadata resource " +
722+
status->m_cget->get_url() +
723+
" is missing 'jwks_uri' string value");
724+
}
725+
auto jwks_uri = iter->second.get<std::string>();
726+
status->m_has_metadata = true;
727+
status->m_state = AsyncStatus::DOWNLOAD_PUBLIC_KEY;
728+
status->m_cget.reset(new internal::SimpleCurlGet());
729+
status->m_cget->perform_start(jwks_uri);
730+
// This should also fall through the next state
701731
}
702-
status->m_cget->get_data(buffer, len);
703-
std::string metadata(buffer, len);
704-
picojson::value json_obj;
705-
auto err = picojson::parse(json_obj, metadata);
706-
if (!err.empty()) {
707-
throw JsonException(
708-
"JSON parse failure when downloading from the metadata URL " +
709-
status->m_cget->get_url() + ": " + err);
710-
}
711-
if (!json_obj.is<picojson::object>()) {
712-
throw JsonException("Metadata resource " +
713-
status->m_cget->get_url() +
714-
" contains "
715-
"improperly-formatted JSON.");
716-
}
717-
auto top_obj = json_obj.get<picojson::object>();
718-
auto iter = top_obj.find("jwks_uri");
719-
if (iter == top_obj.end() || (!iter->second.is<std::string>())) {
720-
throw JsonException("Metadata resource " +
721-
status->m_cget->get_url() +
722-
" is missing 'jwks_uri' string value");
723-
}
724-
auto jwks_uri = iter->second.get<std::string>();
725-
status->m_has_metadata = true;
726-
status->m_state = AsyncStatus::DOWNLOAD_PUBLIC_KEY;
727-
status->m_cget.reset(new internal::SimpleCurlGet());
728-
status->m_cget->perform_start(jwks_uri);
729-
// This should also fall through the next state
730-
}
731732

732-
case AsyncStatus::DOWNLOAD_PUBLIC_KEY: {
733-
auto cget_status = status->m_cget->perform_continue();
734-
if (!cget_status.m_done) {
735-
return std::move(status);
736-
}
737-
if (cget_status.m_status_code != 200) {
738-
throw IssuerLookupException("Failed to retrieve the issuer's key set");
739-
}
733+
case AsyncStatus::DOWNLOAD_PUBLIC_KEY: {
734+
auto cget_status = status->m_cget->perform_continue();
735+
if (!cget_status.m_done) {
736+
return std::move(status);
737+
}
738+
if (cget_status.m_status_code != 200) {
739+
throw IssuerLookupException(
740+
"Failed to retrieve the issuer's key set");
741+
}
740742

741-
status->m_cget->get_data(buffer, len);
742-
auto metadata = std::string(buffer, len);
743-
picojson::value json_obj;
744-
auto err = picojson::parse(json_obj, metadata);
745-
if (!err.empty()) {
746-
throw JsonException("JSON parse failure when downloading from the "
747-
" public key URL " +
748-
status->m_cget->get_url() + ": " + err);
743+
status->m_cget->get_data(buffer, len);
744+
auto metadata = std::string(buffer, len);
745+
picojson::value json_obj;
746+
auto err = picojson::parse(json_obj, metadata);
747+
if (!err.empty()) {
748+
throw JsonException(
749+
"JSON parse failure when downloading from the "
750+
" public key URL " +
751+
status->m_cget->get_url() + ": " + err);
752+
}
753+
status->m_cget.reset();
754+
755+
auto now = std::time(NULL);
756+
// TODO: take expiration time from the cache-control header in the
757+
// response.
758+
759+
int next_update_delta =
760+
configurer::Configuration::get_next_update_delta();
761+
int expiry_delta = configurer::Configuration::get_expiry_delta();
762+
status->m_next_update = now + next_update_delta;
763+
status->m_expires = now + expiry_delta;
764+
status->m_keys = json_obj;
765+
status->m_continue_fetch = false;
766+
status->m_done = true;
767+
status->m_state = AsyncStatus::DONE;
749768
}
750-
status->m_cget.reset();
751-
752-
auto now = std::time(NULL);
753-
// TODO: take expiration time from the cache-control header in the
754-
// response.
755-
756-
int next_update_delta =
757-
configurer::Configuration::get_next_update_delta();
758-
int expiry_delta = configurer::Configuration::get_expiry_delta();
759-
status->m_next_update = now + next_update_delta;
760-
status->m_expires = now + expiry_delta;
761-
status->m_keys = json_obj;
762-
status->m_continue_fetch = false;
763-
status->m_done = true;
764-
status->m_state = AsyncStatus::DONE;
765-
}
766-
case AsyncStatus::DONE:
767-
status->m_done = true;
768-
769-
} // Switch
770-
return std::move(status);
769+
case AsyncStatus::DONE:
770+
status->m_done = true;
771+
772+
} // Switch
773+
return std::move(status);
771774
} catch (const CurlException &e) {
772775
// Rethrow CURL errors during issuer key fetch as IssuerLookupException
773776
// (unless it's already an IssuerLookupException)
774-
if (dynamic_cast<const IssuerLookupException*>(&e)) {
777+
if (dynamic_cast<const IssuerLookupException *>(&e)) {
775778
throw;
776779
}
777780
throw IssuerLookupException(e.what());

0 commit comments

Comments
 (0)