-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multisignature and signaturechain
Signed-off-by: andreas hilti <69210561+andreas-hilti@users.noreply.github.com>
- Loading branch information
1 parent
c06a8c7
commit 787f82c
Showing
14 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/CycloneDX.Core/Json/Converters/SignatureChoiceConverter.cs
This file contains 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,99 @@ | ||
// This file is part of CycloneDX Library for .NET | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the “License”); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an “AS IS” BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) OWASP Foundation. All Rights Reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Contracts; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using CycloneDX.Models; | ||
|
||
namespace CycloneDX.Json.Converters | ||
{ | ||
|
||
|
||
public class SignatureChoiceConverter : JsonConverter<SignatureChoice> | ||
{ | ||
public override SignatureChoice Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.Null) | ||
{ | ||
return null; | ||
} | ||
else if (reader.TokenType == JsonTokenType.StartObject) | ||
{ | ||
var signatureChoice = new SignatureChoice(); | ||
var doc = JsonDocument.ParseValue(ref reader); | ||
if (doc.RootElement.TryGetProperty("signers", out var signersValue)) | ||
{ | ||
var signers = signersValue.Deserialize<List<Signature>>(options); | ||
signatureChoice.Signers = signers; | ||
} | ||
else if (doc.RootElement.TryGetProperty("chain", out var chainValue)) | ||
{ | ||
var chain = chainValue.Deserialize<List<Signature>>(options); | ||
signatureChoice.Chain = chain; | ||
} | ||
else | ||
{ | ||
var signature = doc.Deserialize<Signature>(options); | ||
signatureChoice.Signature = signature; | ||
} | ||
return signatureChoice; | ||
} | ||
else | ||
{ | ||
throw new JsonException(); | ||
} | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
SignatureChoice value, | ||
JsonSerializerOptions options) | ||
{ | ||
Contract.Requires(writer != null); | ||
Contract.Requires(value != null); | ||
|
||
if (value != null) | ||
{ | ||
|
||
if (value.Signers != null) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WritePropertyName("signers"); | ||
JsonSerializer.Serialize(writer, value.Signers, options); | ||
writer.WriteEndObject(); | ||
} | ||
if (value.Chain != null) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WritePropertyName("chain"); | ||
JsonSerializer.Serialize(writer, value.Chain, options); | ||
writer.WriteEndObject(); | ||
} | ||
if (value.Signature != null) | ||
{ | ||
JsonSerializer.Serialize(writer, value.Signature, options); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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