summary refs log tree commit diff
path: root/crypto/src/asn1/esf/SignerAttribute.cs
blob: 03cdd4ba850d4514fb9ed8f6f03c4c1059df21de (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;

using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Asn1.Esf
{
	public class SignerAttribute
		: Asn1Encodable
	{
		private Asn1Sequence			claimedAttributes;
		private AttributeCertificate	certifiedAttributes;

		public static SignerAttribute GetInstance(
			object obj)
		{
			if (obj == null || obj is SignerAttribute)
				return (SignerAttribute) obj;

			if (obj is Asn1Sequence)
				return new SignerAttribute(obj);

			throw new ArgumentException(
				"Unknown object in 'SignerAttribute' factory: "
                + Platform.GetTypeName(obj),
				"obj");
		}

		private SignerAttribute(object obj)
		{
			Asn1Sequence seq = (Asn1Sequence)obj;
			Asn1TaggedObject taggedObject = (Asn1TaggedObject)seq[0];
			if (taggedObject.TagNo == 0)
			{
				claimedAttributes = Asn1Sequence.GetInstance(taggedObject, true);
			}
			else if (taggedObject.TagNo == 1)
			{
				certifiedAttributes = AttributeCertificate.GetInstance(taggedObject);
			}
			else
			{
				throw new ArgumentException("illegal tag.", "obj");
			}
		}

		public SignerAttribute(
			Asn1Sequence claimedAttributes)
		{
			this.claimedAttributes = claimedAttributes;
		}

		public SignerAttribute(
			AttributeCertificate certifiedAttributes)
		{
			this.certifiedAttributes = certifiedAttributes;
		}

		public virtual Asn1Sequence ClaimedAttributes
		{
			get { return claimedAttributes; }
		}

		public virtual AttributeCertificate CertifiedAttributes
		{
			get { return certifiedAttributes; }
		}

		/**
		*
		* <pre>
		*  SignerAttribute ::= SEQUENCE OF CHOICE {
		*      claimedAttributes   [0] ClaimedAttributes,
		*      certifiedAttributes [1] CertifiedAttributes }
		*
		*  ClaimedAttributes ::= SEQUENCE OF Attribute
		*  CertifiedAttributes ::= AttributeCertificate -- as defined in RFC 3281: see clause 4.1.
		* </pre>
		*/
		public override Asn1Object ToAsn1Object()
		{
			return claimedAttributes != null
				?	new DerSequence(new DerTaggedObject(0, claimedAttributes))
				:	new DerSequence(new DerTaggedObject(1, certifiedAttributes));
		}
	}
}