Skip to content

Commit 39289a3

Browse files
committed
Add missing APIs used by gtest.
1 parent aa1fe99 commit 39289a3

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/scitokens.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ int scitoken_set_claim_string(SciToken token, const char *key, const char *value
6767
}
6868

6969

70+
void scitoken_set_serialize_profile(SciToken token, SciTokenProfile profile) {
71+
scitoken_set_serialize_mode(token, profile);
72+
}
73+
74+
7075
void scitoken_set_serialize_mode(SciToken token, SciTokenProfile profile) {
7176
scitokens::SciToken *real_token = reinterpret_cast<scitokens::SciToken*>(token);
7277
if (real_token == nullptr) {return;}
@@ -75,6 +80,14 @@ void scitoken_set_serialize_mode(SciToken token, SciTokenProfile profile) {
7580
}
7681

7782

83+
void scitoken_set_deserialize_profile(SciToken token, SciTokenProfile profile) {
84+
scitokens::SciToken *real_token = reinterpret_cast<scitokens::SciToken*>(token);
85+
if (real_token == nullptr) {return;}
86+
87+
real_token->set_deserialize_mode(static_cast<scitokens::SciToken::Profile>(profile));
88+
}
89+
90+
7891
int scitoken_get_claim_string(const SciToken token, const char *key, char **value, char **err_msg) {
7992
scitokens::SciToken *real_token = reinterpret_cast<scitokens::SciToken*>(token);
8093
std::string claim_str;
@@ -150,6 +163,18 @@ int scitoken_deserialize(const char *value, SciToken *token, char const* const*
150163
scitokens::SciTokenKey key;
151164
scitokens::SciToken *real_token = new scitokens::SciToken(key);
152165

166+
int retval = scitoken_deserialize_v2(value, reinterpret_cast<SciToken>(real_token), allowed_issuers, err_msg);
167+
if (retval) {
168+
delete real_token;
169+
} else {
170+
*token = real_token;
171+
}
172+
return retval;
173+
}
174+
175+
int scitoken_deserialize_v2(const char *value, SciToken token, char const* const* allowed_issuers, char **err_msg) {
176+
scitokens::SciToken *real_token = reinterpret_cast<scitokens::SciToken*>(token);
177+
153178
std::vector<std::string> allowed_issuers_vec;
154179
if (allowed_issuers != nullptr) {
155180
for (int idx=0; allowed_issuers[idx]; idx++) {
@@ -165,7 +190,6 @@ int scitoken_deserialize(const char *value, SciToken *token, char const* const*
165190
}
166191
return -1;
167192
}
168-
*token = real_token;
169193
return 0;
170194
}
171195

src/scitokens.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ int scitoken_serialize(const SciToken token, char **value, char **err_msg);
5757
* Set the profile used for serialization; if COMPAT mode is used, then
5858
* the library default is utilized (currently, scitokens 1.0).
5959
*/
60+
void scitoken_set_serialize_profile(SciToken token, SciTokenProfile profile);
61+
6062
void scitoken_set_serialize_mode(SciToken token, SciTokenProfile profile);
6163

64+
void scitoken_set_deserialize_profile(SciToken token, SciTokenProfile profile);
65+
6266
int scitoken_deserialize(const char *value, SciToken *token, char const* const* allowed_issuers, char **err_msg);
6367

68+
int scitoken_deserialize_v2(const char *value, SciToken token, char const* const* allowed_issuers, char **err_msg);
69+
6470
int scitoken_store_public_ec_key(const char *issuer, const char *keyid, const char *value, char **err_msg);
6571

6672
Validator validator_create();

src/scitokens_internal.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ SciToken::deserialize(const std::string &data, const std::vector<std::string> al
341341
scitokens::Validator val;
342342
val.add_allowed_issuers(allowed_issuers);
343343
val.set_validate_all_claims_scitokens_1(false);
344+
val.set_validate_profile(m_deserialize_profile);
344345
val.verify(*m_decoded);
345346

346347
// Set all the claims

src/scitokens_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ friend class scitokens::Validator;
134134
m_serialize_profile = profile;
135135
}
136136

137+
void
138+
set_deserialize_mode(Profile profile) {
139+
m_deserialize_profile = profile;
140+
}
141+
137142
const jwt::claim
138143
get_claim(const std::string &key) {
139144
return m_claims[key];
@@ -205,6 +210,7 @@ friend class scitokens::Validator;
205210
int m_lifetime{600};
206211
Profile m_profile{Profile::SCITOKENS_1_0};
207212
Profile m_serialize_profile{Profile::COMPAT};
213+
Profile m_deserialize_profile{Profile::COMPAT};
208214
std::unordered_map<std::string, jwt::claim> m_claims;
209215
std::unique_ptr<jwt::decoded_jwt> m_decoded;
210216
SciTokenKey &m_key;

0 commit comments

Comments
 (0)