-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
The BinaryData format property can't handle byte[] data properly. #33804
Comments
After investigation, here is what I found from this issue:
string sample = "this is the sample code.";
byte[] input = UTF8Encoding.UTF8.GetBytes($"\"{sample}\"");
// byte[] input = UTF8Encoding.UTF8.GetBytes(sample); wrong way to get the byte array when faced with a string
BinaryData data = BinaryData.FromBytes(input);
Based on above findings, we need to update the code so that the serialization could work as expected: Thumbprint = BinaryData.FromString($"\"{Convert.ToHexString(certificate.Properties.X509Thumbprint)}\""); Finally, I think we really need a full documentation for BinaryData and this documentation could be part of the management plane SDK FAQ, and this documentation should contain below contents at least:
|
There is nothing wrong with var str = "hello world";
var encodedStr = Base64Url.EncodeString(str);
var decodedBytes = Base64Url.Decode(encodedStr);
var result = BinaryData.FromBytes(decodedBytes).ToString();
Assert.AreNotEqual(str, result); The error was thrown from JSON serialization, because the original content of X509Thumbprint was a UTF-16 format string and we are using JsonElement in the implementation, which is expecting UTF-8 format. The user can convert the original string to a hex string, which is what the Azure Portal display text does, then it can be serialized by Then the question is, does the server side always expect a hex string for Thumbprint? If so, we should return a hex string for X509Thumbprint from GetCertificateAsync in the first place. @heaths Could you provide your thoughts here? Thanks! |
I'm not sure how Thumbprints, yes, are typically represented as a hash string. You'd have to talk with the CDN folks about how their thumbprint is represented and should be used, though. |
In mgmt, we will add a new property named |
@live1206 that is not congruent with the latest conversation between @KrzysztofCwalina, @m-nash, and myself. Has the plan changed? As Krzysztof noted, he doesn't agree we should add a simple property getter that converts the |
To clarify my position: we should try to endup with one representation (either string or byte[]). I originally suggested byte[], but if string is more common in these scenarios, string (hex string) is fine with me. What I think we should avoid is having two representation and adding conversion APIs. |
Key Vault SDK long ago shipped a property of type public string X509ThumbprintAsHexString => Convert.ToHexString(X509Thumbprint); But you said,
Seems we'd want congruent properties to avoid confusion. |
Agreed if we think hex string is the correct common format then adding the extra property in keyvault and switching from BinaryData to string in mgmt would solve the iterop issue here. |
Ping @KrzysztofCwalina for feedback on the last couple comments. /cc @tg-msft |
I am fine with using hex string as the main interchange format (for thumbprints). |
@KrzysztofCwalina the specific question was whether the Key Vault SDK should add a property that just returns the hex string or not. Previously you were opposed. |
I was opposed to having both representations being "first class". I was (and am) arguing for picking one representation and then evolving the APIs in that direction. I don't think we should have both representations exposed prominently and asking users to pick. |
The Key Vault SDK already returns a |
Discussing offline, we've decided to add a @m-nash let's use this bug to track the management side. I'll open a new one for the data plane SDK. |
The new version of corresponding SDKs will be released soon. |
The text was updated successfully, but these errors were encountered: