diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-07-01 20:31:14 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-07-01 20:31:14 +0700 |
commit | 192a98faa4536772b03a5cd59b6e4ab4a2ec2461 (patch) | |
tree | 9a254e2c0d7ca92b7e8108c554c2c8dbc547f79d /crypto/src/asn1/DLSequence.cs | |
parent | Refactoring in Asn1.X500 (diff) | |
download | BouncyCastle.NET-ed25519-192a98faa4536772b03a5cd59b6e4ab4a2ec2461.tar.xz |
Asn1Sequence subclass static methods
Diffstat (limited to 'crypto/src/asn1/DLSequence.cs')
-rw-r--r-- | crypto/src/asn1/DLSequence.cs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/crypto/src/asn1/DLSequence.cs b/crypto/src/asn1/DLSequence.cs index 05b634f57..0c2431db1 100644 --- a/crypto/src/asn1/DLSequence.cs +++ b/crypto/src/asn1/DLSequence.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 new DLSequence FromElements(Asn1Encodable[] elements) + public static new DLSequence FromElements(Asn1Encodable[] elements) { - return elements.Length < 1 ? Empty : new DLSequence(elements, clone: false); + if (elements == null) + throw new ArgumentNullException(nameof(elements)); + + return elements.Length < 1 ? Empty : new DLSequence(elements); + } + + public static new DLSequence FromElementsOptional(Asn1Encodable[] elements) + { + if (elements == null) + return null; + + return elements.Length < 1 ? Empty : new DLSequence(elements); } public static new DLSequence FromSequence(Asn1Sequence sequence) @@ -33,7 +44,7 @@ namespace Org.BouncyCastle.Asn1 if (sequence is DLSequence dlSequence) return dlSequence; - return FromElements(sequence.m_elements); + return WithElements(sequence.m_elements); } public static new DLSequence FromVector(Asn1EncodableVector elementVector) @@ -41,6 +52,16 @@ namespace Org.BouncyCastle.Asn1 return elementVector.Count < 1 ? Empty : new DLSequence(elementVector); } + public static new DLSequence Map(Asn1Sequence sequence, Func<Asn1Encodable, Asn1Encodable> func) + { + return sequence.Count < 1 ? Empty : new DLSequence(sequence.MapElements(func), clone: false); + } + + internal static new DLSequence WithElements(Asn1Encodable[] elements) + { + return elements.Length < 1 ? Empty : new DLSequence(elements, clone: false); + } + /** * create an empty sequence */ |