summary refs log tree commit diff
path: root/crypto/src/asn1/cms/Attributes.cs
blob: 5b6b1303486e255fb99dd181b3d08c98b8fee6fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;

namespace Org.BouncyCastle.Asn1.Cms
{
    public class Attributes
        : Asn1Encodable
    {
        private readonly Asn1Set attributes;

        private Attributes(Asn1Set attributes)
        {
            this.attributes = attributes;
        }

        public Attributes(Asn1EncodableVector v)
        {
            attributes = new BerSet(v);
        }

        public static Attributes GetInstance(object obj)
        {
            if (obj is Attributes)
                return (Attributes)obj;

            if (obj != null)
                return new Attributes(Asn1Set.GetInstance(obj));

            return null;
        }

        public virtual Attribute[] GetAttributes()
        {
            Attribute[] rv = new Attribute[attributes.Count];

            for (int i = 0; i != rv.Length; i++)
            {
                rv[i] = Attribute.GetInstance(attributes[i]);
            }

            return rv;
        }

        /**
         * <pre>
         * Attributes ::=
         *   SET SIZE(1..MAX) OF Attribute -- according to RFC 5652
         * </pre>
         * @return
         */
        public override Asn1Object ToAsn1Object()
        {
            return attributes;
        }
    }
}