Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep nlohmann::json private #371

Merged
merged 4 commits into from
Oct 25, 2023
Merged

keep nlohmann::json private #371

merged 4 commits into from
Oct 25, 2023

Conversation

glhewett
Copy link
Contributor

@glhewett glhewett commented Sep 13, 2023

We want libraries that have dependencies on mlspp to not be forced to download and install nlohmann::json. This gets messy when other json libraries are involved. This PR will remove json libraries from public headers and remove the link dependency for the library.

@bifurcation bifurcation marked this pull request as ready for review October 17, 2023 20:54
@bifurcation
Copy link
Contributor

@glhewett Could you make a trivial push here so that the full CI runs, now that it's not marked as draft?

@glhewett
Copy link
Contributor Author

@bifurcation - It is not working, yet. I would rather close the PR. You have my permission to close it once you read this. I will make sure we have an issue to track it.

Copy link
Contributor

@bifurcation bifurcation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor suggestions, otherwise LGTM.

lib/hpke/test/userinfo_vc.cpp Outdated Show resolved Hide resolved
Comment on lines +310 to +311
address_opt = UserInfoClaimsAddress::from_json(
cred_subject_json.at(address_attr).dump());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this back and forth between strings and JSON. Maybe there's some way to have static functions that take json? So that they're hidden from callers but we can still use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the difficult thing about this library. If we have any use of our json library in the public api's then the consumer will have to build and link to our json library. If they use another library then they would have to convert. I think you understand that. I will think about the static function that might do the conversion. Out only options in the signature of a function is string or bytes. what do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I had in mind was something like:

// Standard from_json method so that `json::get` works
static void from_json(const json& j, UserInfoClaimsAddress& addr) {
  // current body of UserInfoClaimsAddress::from_json
}

static void from_json(const json& j, UserInfoClaims& addr) { 
  // current body of UserInfoClaims::from_json
  // including using get_optional<UserInfoClaimsAddress>(...)
}

// String methods just call through to JSON methods
UserInfoClaims
UserInfoClaims::from_json(const std::string& cred_subject) {
  return json::parse(cred_subject).get<UserInfoClaims>();
}

UserInfoClaimsAddress
UserInfoClaimsAddress::from_json(const std::string& address) {
  return json::parse(address).get<UserInfoClaimsAddress>();
}

Co-authored-by: Richard Barnes <rlb@ipv.sx>
@glhewett glhewett marked this pull request as draft October 25, 2023 02:14
@glhewett glhewett marked this pull request as ready for review October 25, 2023 13:57
Comment on lines +178 to +179
const auto userinfo_claims =
UserInfoClaims::from_json(credentialSubject.dump());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same raw string trick here. (Raw strings can span multiple lines.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the original json as the known answer for the tests. The tests in that section seem to only test that the strings get shuffled around correctly.

@bifurcation bifurcation merged commit c2f1f17 into main Oct 25, 2023
8 checks passed
@glhewett
Copy link
Contributor Author

created #393 to optimize implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants