diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-07-18 18:29:42 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-07-18 18:29:42 +0700 |
commit | 8119dba914a3aa08cd1ce7b24b757e95269d3aaf (patch) | |
tree | 26a50fe08c3d9aff219776675a0dd015f38f38e2 /crypto/src/asn1/cms/Attributes.cs | |
parent | Custom encoding classes for tagged objects (diff) | |
download | BouncyCastle.NET-ed25519-8119dba914a3aa08cd1ce7b24b757e95269d3aaf.tar.xz |
Asn1.Tsp updates from bc-java
Diffstat (limited to 'crypto/src/asn1/cms/Attributes.cs')
-rw-r--r-- | crypto/src/asn1/cms/Attributes.cs | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/crypto/src/asn1/cms/Attributes.cs b/crypto/src/asn1/cms/Attributes.cs index 5b6b13034..010684158 100644 --- a/crypto/src/asn1/cms/Attributes.cs +++ b/crypto/src/asn1/cms/Attributes.cs @@ -5,41 +5,34 @@ namespace Org.BouncyCastle.Asn1.Cms public class Attributes : Asn1Encodable { - private readonly Asn1Set attributes; - - private Attributes(Asn1Set attributes) + public static Attributes GetInstance(object obj) { - this.attributes = attributes; + if (obj == null) + return null; + if (obj is Attributes attributes) + return attributes; + return new Attributes(Asn1Set.GetInstance(obj)); } - public Attributes(Asn1EncodableVector v) + public static Attributes GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { - attributes = new BerSet(v); + return GetInstance(Asn1Set.GetInstance(taggedObject, declaredExplicit)); } - public static Attributes GetInstance(object obj) - { - if (obj is Attributes) - return (Attributes)obj; + private readonly Asn1Set m_attributes; - if (obj != null) - return new Attributes(Asn1Set.GetInstance(obj)); - - return null; + private Attributes(Asn1Set attributes) + { + m_attributes = attributes; } - public virtual Attribute[] GetAttributes() + public Attributes(Asn1EncodableVector v) { - Attribute[] rv = new Attribute[attributes.Count]; - - for (int i = 0; i != rv.Length; i++) - { - rv[i] = Attribute.GetInstance(attributes[i]); - } - - return rv; + m_attributes = new BerSet(v); } + public virtual Attribute[] GetAttributes() => m_attributes.MapElements(Attribute.GetInstance); + /** * <pre> * Attributes ::= @@ -47,9 +40,6 @@ namespace Org.BouncyCastle.Asn1.Cms * </pre> * @return */ - public override Asn1Object ToAsn1Object() - { - return attributes; - } + public override Asn1Object ToAsn1Object() => m_attributes; } } |