Client Encryption(Custom): Adds fix for deserialization issue for invalid date type. (#2834)
This PR adds a fix to pass serialization settings to disable date parsing during deserialization, which is already being done during serialization but I missed to pass the same during deserialization. Adds change log for custom encryption package and bumps up package version.
This commit is contained in:
Родитель
89f8148805
Коммит
47e9ee738f
|
@ -6,7 +6,7 @@
|
|||
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
|
||||
<DirectVersion>3.23.1</DirectVersion>
|
||||
<EncryptionVersion>1.0.0-previewV17</EncryptionVersion>
|
||||
<CustomEncryptionVersion>1.0.0-preview</CustomEncryptionVersion>
|
||||
<CustomEncryptionVersion>1.0.0-preview02</CustomEncryptionVersion>
|
||||
<HybridRowVersion>1.1.0-preview3</HybridRowVersion>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<AboveDirBuildProps>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</AboveDirBuildProps>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
Preview features are treated as a separate branch and will not be included in the official release until the feature is ready. Each preview release lists all the additional features that are enabled.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
### <a name="1.0.0-preview02"/> [1.0.0-preview02](https://www.nuget.org/packages/Microsoft.Azure.Cosmos.Encryption.custom/1.0.0-preview02) - 2021-10-29
|
||||
|
||||
#### Fixes
|
||||
- [#2834](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/2834) Adds fix for deserialization issue for invalid date type.
|
||||
|
||||
|
||||
### <a name="1.0.0-preview"/> [1.0.0-preview](https://www.nuget.org/packages/Microsoft.Azure.Cosmos.Encryption.custom/1.0.0-preview) - 2021-10-20
|
||||
- First preview of custom client-side encryption feature. See https://aka.ms/CosmosClientEncryption for more information on client-side encryption support in Azure Cosmos DB.
|
|
@ -21,11 +21,17 @@ namespace Microsoft.Azure.Cosmos.Encryption.Custom
|
|||
/// </summary>
|
||||
internal static class EncryptionProcessor
|
||||
{
|
||||
internal static readonly CosmosJsonDotNetSerializer BaseSerializer = new CosmosJsonDotNetSerializer(
|
||||
new JsonSerializerSettings()
|
||||
{
|
||||
DateParseHandling = DateParseHandling.None,
|
||||
});
|
||||
private static readonly SqlSerializerFactory SqlSerializerFactory = new SqlSerializerFactory();
|
||||
|
||||
// UTF-8 encoding.
|
||||
private static readonly SqlVarCharSerializer SqlVarCharSerializer = new SqlVarCharSerializer(size: -1, codePageCharacterEncoding: 65001);
|
||||
|
||||
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings()
|
||||
{
|
||||
DateParseHandling = DateParseHandling.None,
|
||||
};
|
||||
|
||||
internal static readonly CosmosJsonDotNetSerializer BaseSerializer = new CosmosJsonDotNetSerializer(JsonSerializerSettings);
|
||||
|
||||
/// <remarks>
|
||||
/// If there isn't any PathsToEncrypt, input stream will be returned without any modification.
|
||||
|
@ -469,11 +475,6 @@ namespace Microsoft.Azure.Cosmos.Encryption.Custom
|
|||
|
||||
private static (TypeMarker, byte[]) Serialize(JToken propertyValue)
|
||||
{
|
||||
SqlSerializerFactory sqlSerializerFactory = new SqlSerializerFactory();
|
||||
|
||||
// UTF-8 encoding.
|
||||
SqlVarCharSerializer sqlVarCharSerializer = new SqlVarCharSerializer(size: -1, codePageCharacterEncoding: 65001);
|
||||
|
||||
switch (propertyValue.Type)
|
||||
{
|
||||
case JTokenType.Undefined:
|
||||
|
@ -483,17 +484,17 @@ namespace Microsoft.Azure.Cosmos.Encryption.Custom
|
|||
Debug.Assert(false, "Null type should have been handled by caller");
|
||||
return (TypeMarker.Null, null);
|
||||
case JTokenType.Boolean:
|
||||
return (TypeMarker.Boolean, sqlSerializerFactory.GetDefaultSerializer<bool>().Serialize(propertyValue.ToObject<bool>()));
|
||||
return (TypeMarker.Boolean, SqlSerializerFactory.GetDefaultSerializer<bool>().Serialize(propertyValue.ToObject<bool>()));
|
||||
case JTokenType.Float:
|
||||
return (TypeMarker.Double, sqlSerializerFactory.GetDefaultSerializer<double>().Serialize(propertyValue.ToObject<double>()));
|
||||
return (TypeMarker.Double, SqlSerializerFactory.GetDefaultSerializer<double>().Serialize(propertyValue.ToObject<double>()));
|
||||
case JTokenType.Integer:
|
||||
return (TypeMarker.Long, sqlSerializerFactory.GetDefaultSerializer<long>().Serialize(propertyValue.ToObject<long>()));
|
||||
return (TypeMarker.Long, SqlSerializerFactory.GetDefaultSerializer<long>().Serialize(propertyValue.ToObject<long>()));
|
||||
case JTokenType.String:
|
||||
return (TypeMarker.String, sqlVarCharSerializer.Serialize(propertyValue.ToObject<string>()));
|
||||
return (TypeMarker.String, SqlVarCharSerializer.Serialize(propertyValue.ToObject<string>()));
|
||||
case JTokenType.Array:
|
||||
return (TypeMarker.Array, sqlVarCharSerializer.Serialize(propertyValue.ToString()));
|
||||
return (TypeMarker.Array, SqlVarCharSerializer.Serialize(propertyValue.ToString()));
|
||||
case JTokenType.Object:
|
||||
return (TypeMarker.Object, sqlVarCharSerializer.Serialize(propertyValue.ToString()));
|
||||
return (TypeMarker.Object, SqlVarCharSerializer.Serialize(propertyValue.ToString()));
|
||||
default:
|
||||
throw new InvalidOperationException($" Invalid or Unsupported Data Type Passed : {propertyValue.Type}");
|
||||
}
|
||||
|
@ -505,30 +506,25 @@ namespace Microsoft.Azure.Cosmos.Encryption.Custom
|
|||
JObject jObject,
|
||||
string key)
|
||||
{
|
||||
SqlSerializerFactory sqlSerializerFactory = new SqlSerializerFactory();
|
||||
|
||||
// UTF-8 encoding.
|
||||
SqlVarCharSerializer sqlVarCharSerializer = new SqlVarCharSerializer(size: -1, codePageCharacterEncoding: 65001);
|
||||
|
||||
switch (typeMarker)
|
||||
{
|
||||
case TypeMarker.Boolean:
|
||||
jObject.Add(key, sqlSerializerFactory.GetDefaultSerializer<bool>().Deserialize(serializedBytes));
|
||||
jObject.Add(key, SqlSerializerFactory.GetDefaultSerializer<bool>().Deserialize(serializedBytes));
|
||||
break;
|
||||
case TypeMarker.Double:
|
||||
jObject.Add(key, sqlSerializerFactory.GetDefaultSerializer<double>().Deserialize(serializedBytes));
|
||||
jObject.Add(key, SqlSerializerFactory.GetDefaultSerializer<double>().Deserialize(serializedBytes));
|
||||
break;
|
||||
case TypeMarker.Long:
|
||||
jObject.Add(key, sqlSerializerFactory.GetDefaultSerializer<long>().Deserialize(serializedBytes));
|
||||
jObject.Add(key, SqlSerializerFactory.GetDefaultSerializer<long>().Deserialize(serializedBytes));
|
||||
break;
|
||||
case TypeMarker.String:
|
||||
jObject.Add(key, sqlVarCharSerializer.Deserialize(serializedBytes));
|
||||
jObject.Add(key, SqlVarCharSerializer.Deserialize(serializedBytes));
|
||||
break;
|
||||
case TypeMarker.Array:
|
||||
jObject.Add(key, JsonConvert.DeserializeObject<JArray>(sqlVarCharSerializer.Deserialize(serializedBytes)));
|
||||
jObject.Add(key, JsonConvert.DeserializeObject<JArray>(SqlVarCharSerializer.Deserialize(serializedBytes), JsonSerializerSettings));
|
||||
break;
|
||||
case TypeMarker.Object:
|
||||
jObject.Add(key, JsonConvert.DeserializeObject<JObject>(sqlVarCharSerializer.Deserialize(serializedBytes)));
|
||||
jObject.Add(key, JsonConvert.DeserializeObject<JObject>(SqlVarCharSerializer.Deserialize(serializedBytes), JsonSerializerSettings));
|
||||
break;
|
||||
default:
|
||||
Debug.Fail(string.Format("Unexpected type marker {0}", typeMarker));
|
||||
|
|
Загрузка…
Ссылка в новой задаче