From 192a98faa4536772b03a5cd59b6e4ab4a2ec2461 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 1 Jul 2024 20:31:14 +0700 Subject: Asn1Sequence subclass static methods --- crypto/src/asn1/DerSequence.cs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'crypto/src/asn1/DerSequence.cs') diff --git a/crypto/src/asn1/DerSequence.cs b/crypto/src/asn1/DerSequence.cs index 4a4aee434..a6ecb3ffa 100644 --- a/crypto/src/asn1/DerSequence.cs +++ b/crypto/src/asn1/DerSequence.cs @@ -19,13 +19,24 @@ namespace Org.BouncyCastle.Asn1 case 1: return FromSequence(sequences[0]); default: - return FromElements(ConcatenateElements(sequences)); + return WithElements(ConcatenateElements(sequences)); } } - internal static DerSequence FromElements(Asn1Encodable[] elements) + public static DerSequence FromElements(Asn1Encodable[] elements) { - return elements.Length < 1 ? Empty : new DerSequence(elements, clone: false); + if (elements == null) + throw new ArgumentNullException(nameof(elements)); + + return elements.Length < 1 ? Empty : new DerSequence(elements); + } + + public static DerSequence FromElementsOptional(Asn1Encodable[] elements) + { + if (elements == null) + return null; + + return elements.Length < 1 ? Empty : new DerSequence(elements); } public static DerSequence FromSequence(Asn1Sequence sequence) @@ -33,7 +44,7 @@ namespace Org.BouncyCastle.Asn1 if (sequence is DerSequence derSequence) return derSequence; - return FromElements(sequence.m_elements); + return WithElements(sequence.m_elements); } public static DerSequence FromVector(Asn1EncodableVector elementVector) @@ -41,6 +52,16 @@ namespace Org.BouncyCastle.Asn1 return elementVector.Count < 1 ? Empty : new DerSequence(elementVector); } + public static DerSequence Map(Asn1Sequence sequence, Func func) + { + return sequence.Count < 1 ? Empty : new DerSequence(sequence.MapElements(func), clone: false); + } + + internal static DerSequence WithElements(Asn1Encodable[] elements) + { + return elements.Length < 1 ? Empty : new DerSequence(elements, clone: false); + } + /** * create an empty sequence */ -- cgit 1.4.1