This repository was archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Fix public key token serialization issue #800
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/lib/Microsoft.Fx.Portability/Utils/JsonConverters/JsonPublicKeyTokenConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.Fx.Portability.ObjectModel; | ||
| using Newtonsoft.Json; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Security.Cryptography.X509Certificates; | ||
| using System.Text; | ||
|
|
||
| namespace Microsoft.Fx.Portability.Utils.JsonConverters | ||
| { | ||
| internal class JsonPublicKeyTokenConverter : JsonConverter<PublicKeyToken> | ||
| { | ||
| public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
| { | ||
| string publicKeyTokenString = serializer | ||
| .Deserialize<string>(reader); | ||
| return PublicKeyToken.Parse(publicKeyTokenString); | ||
| } | ||
|
|
||
| public override void WriteJson(JsonWriter writer, object obj, JsonSerializer serializer) | ||
| { | ||
| PublicKeyToken pkToken = (PublicKeyToken)obj; | ||
| serializer.Serialize(writer, pkToken.ToString()); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this serialization used and what is it optimized for? Serializing as a string would be a much more efficient and easy to deal with encoding, but this looks like it would work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably used in returning a response or sending a request. Must not have any tests associated with it so my change wasn't caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twsouthwick This PR fix the current problem if both client and server sides using the new binary contains PublicKeyToken struct, but if old version of client without knowledge of PublicKeyToken works with new Server, the serialization will still break. Looks like PR #784 broke backward compat serialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to have a converter that would work for both. Do a string serialization (maybe that's what @marklio was referring to) and it should then work for backwards compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can serialize with
PublicKeyToken.ToString()and deserialize withPublicKeyToken.Parse(string). That should provide round trippingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted a new commit. Verified working with backward compat.