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

Initial support for std::error_code #86

Merged
merged 9 commits into from
Jul 21, 2020
Merged

Initial support for std::error_code #86

merged 9 commits into from
Jul 21, 2020

Conversation

Thalhammer
Copy link
Owner

Initial support for error_code overloads.
@prince-chrismc Wanna take a quick look to check if I maybe missed something ?

Copy link
Collaborator

@prince-chrismc prince-chrismc left a comment

Choose a reason for hiding this comment

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

Thank you for the invite firstly! I want to help make this project successful 😄

All in all it looks good. Just a few editorial comments.

I noticed the exceptions and now the error_codes for the "algorithms" are outside of that namespace, would you think they could be moved to that namespace?

include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
#if OPENSSL_VERSION_NUMBER <= 0x10100003L
std::unique_ptr<BIO, decltype(&BIO_free_all)> certbio(BIO_new_mem_buf(const_cast<char*>(certstr.data()), certstr.size()), BIO_free_all);
#else
std::unique_ptr<BIO, decltype(&BIO_free_all)> certbio(BIO_new_mem_buf(certstr.data(), static_cast<int>(certstr.size())), BIO_free_all);
#endif
std::unique_ptr<BIO, decltype(&BIO_free_all)> keybio(BIO_new(BIO_s_mem()), BIO_free_all);
if(!certbio || !keybio) {
ec = error::rsa_error::create_mem_bio_failed;
Copy link
Collaborator

Choose a reason for hiding this comment

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

could be more generic than rsa_error

All the headers return an rsa_error, do any of the other algos use the helpers? I don't see any in the diff

include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
include/jwt-cpp/jwt.h Outdated Show resolved Hide resolved
@Thalhammer
Copy link
Owner Author

Thalhammer commented Jul 16, 2020

Thank you for the invite firstly! I want to help make this project successful

Well since you already touched/wrote like half of the codebase and I never had any real complaints I think thats just fair.

I noticed the exceptions and now the error_codes for the "algorithms" are outside of that namespace, would you think they could be moved to that namespace?

I though about that, but if you have catch blocks moving it means users have to change their code. But thinking about it we have breaking changes for the next release anyway.
I think its a good thing to keep all the error stuff together in its own namespace, rather than putting it in the algorithm namespace.

I"ll look through and change your suggestions later.

@prince-chrismc
Copy link
Collaborator

I though about that, but if you have catch blocks moving it means users have to change their code.

💯 it does not add to the UX either,

But thinking about it we have breaking changes for the next release anyway.

I don't actually see any API breaks, it might be worth reviewing to make sure. Very little test code changed.

I think its a good thing to keep all the error stuff together in its own namespace, rather than putting it in the algorithm namespace.

I am certainly in favor of that!

@Thalhammer
Copy link
Owner Author

Maybe we could move all exception types to the error namespace and just typedef them in the jwt namespace ?

@prince-chrismc
Copy link
Collaborator

prince-chrismc commented Jul 17, 2020

Maybe we could move all exception types to the error namespace and just typedef them in the jwt namespace ?

namespace error
{
    //rsa_expection...
    //ecdsa_expection...
}

using rsa_exception = error::rsa_exception;
using ecdsa_expection = error::ecdsa_expection;

🤔

That would be a great alternative!

@prince-chrismc
Copy link
Collaborator

Looking at the coverage the biggest missed count goes to failed openssl calls. which is not exactly easy to test.

Perhaps a few of them could be marks with these so they are not counted

@Thalhammer
Copy link
Owner Author

Looking at the coverage the biggest missed count goes to failed openssl calls. which is not exactly easy to test.

I already have a unit test in the working to test those. However it's a bit hacky, so I'd like to clean it up a bit more and do it in a different PR. Basically what I do is I override all OpenSSL functions we use and have a bitmask which decides when it should fail. If it should fail I return one of the error codes as documented by Openssl and if not I call the original function. However this method only works on linux, which is fine I guess ?

@prince-chrismc
Copy link
Collaborator

However this method only works on linux, which is fine I guess ?

Absolutely, if we add windows tests, that can always be #ifndef _WIN32 to remove them

@Thalhammer
Copy link
Owner Author

@prince-chrismc Think I can merge this ?

Copy link
Collaborator

@prince-chrismc prince-chrismc left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

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.

None yet

2 participants