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

General code refactoring #19

Merged
merged 5 commits into from
Jul 12, 2015
Merged

General code refactoring #19

merged 5 commits into from
Jul 12, 2015

Conversation

abatishchev
Copy link
Member

No description provided.

@mikelehen
Copy link
Contributor

Hey, thanks for all the PR's! I'll probably take a look this weekend and try to get these merged and push out a new release on NuGet.

if (payloadData.TryGetValue("exp", out value) && value != null)
{
// safely unpack a boxed int
if (!(value is int))
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm. I suspect this isn't exactly identical. What if it's a long or a uint? Should we support float, double, etc.? There are probably a number of cases that would have been allowed before but not now, so I'm nervous about changing this.

Copy link
Member Author

Choose a reason for hiding this comment

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

My tests show that it won't work either way, e.g.:

int f = (int)(object)5f;
int d = (int)(object)5d;
int m = (int)(object)5m;

If you box long, uint, etc. and then try to unbox as int it will throw IvalidCastException.

So only int will work. I believe the approach I propose would be more efficient and readable.

Another way could be this:

int? i = o as int?;
if (i.HasValue)
    // use i.Value

but it's less efficient I was told.

@mikelehen
Copy link
Contributor

I have concerns about one change, but otherwise looks fine. Also, there are merge conflicts now since I waited so long to review. Sorry!

@abatishchev
Copy link
Member Author

I'm familiar with some Git magic but not with everything :) How can I merge your master and my branch?

It seems I need to configure the upstream and then I'll be able to sync the fork.

@abatishchev abatishchev reopened this May 19, 2015
@abatishchev
Copy link
Member Author

I hate resolving conflicts. And don't know how to do it well.

So I simply rolled everything back, updated from the upstream and applied them once again. Please check take a look once again.

Also I split the changes to Verify() into few commits:

  • extracting into a method
  • replacing try-catch with if-is

@abatishchev
Copy link
Member Author

Hey, any chance to review and merge, please?

}

var secondsSinceEpoch = Math.Round((DateTime.UtcNow - UnixEpoch).TotalSeconds);
if (secondsSinceEpoch >= (int)value)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code may have been updated since you originally started this PR so that now it does Convert.ToInt32() which is more permissive than "is int" and "(int)value". I think Convert.ToInt32() is probably better, since it'll handle longs and whatnot.

@abatishchev
Copy link
Member Author

I'll work on this in next few days.

@abatishchev
Copy link
Member Author

Please check it out. I moved the code extracting and validating exp into separate branch, see #28.

@mikelehen
Copy link
Contributor

Looks good to me. Thanks!

mikelehen added a commit that referenced this pull request Jul 12, 2015
@mikelehen mikelehen merged commit cfad0ab into jwt-dotnet:master Jul 12, 2015
@abatishchev
Copy link
Member Author

Awesome, thanks! What do you think about the next one?

@abatishchev abatishchev deleted the refactoring-1 branch July 12, 2015 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants