summary refs log tree commit diff
path: root/crypto/src/tsp/TimeStampTokenInfo.cs
blob: cdef826bc299718c5984463e972c39aed49951c6 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;

using Org.BouncyCastle.Asn1.Tsp;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Math;

namespace Org.BouncyCastle.Tsp
{
	public class TimeStampTokenInfo
	{
		private TstInfo		tstInfo;
		private DateTime	genTime;

		public TimeStampTokenInfo(
			TstInfo tstInfo)
		{
			this.tstInfo = tstInfo;

			try
			{
				this.genTime = tstInfo.GenTime.ToDateTime();
			}
			catch (Exception e)
			{
				throw new TspException("unable to parse genTime field: " + e.Message);
			}
		}

		public bool IsOrdered
		{
			get { return tstInfo.Ordering.IsTrue; }
		}

		public Accuracy Accuracy
		{
			get { return tstInfo.Accuracy; }
		}

		public DateTime GenTime
		{
			get { return genTime; }
		}

		public GenTimeAccuracy GenTimeAccuracy
		{
			get
			{
				return this.Accuracy == null
					?	null
					:	new GenTimeAccuracy(this.Accuracy);
			}
		}

		public string Policy
		{
			get { return tstInfo.Policy.Id; }
		}

		public BigInteger SerialNumber
		{
			get { return tstInfo.SerialNumber.Value; }
		}

		public GeneralName Tsa
		{
			get { return tstInfo.Tsa; }
		}

		/**
		 * @return the nonce value, null if there isn't one.
		 */
		public BigInteger Nonce
		{
			get
			{
				return tstInfo.Nonce == null
					?	null
					:	tstInfo.Nonce.Value;
			}
		}

		public AlgorithmIdentifier HashAlgorithm
		{
			get { return tstInfo.MessageImprint.HashAlgorithm; }
		}

		public string MessageImprintAlgOid
		{
            get { return tstInfo.MessageImprint.HashAlgorithm.Algorithm.Id; }
		}

		public byte[] GetMessageImprintDigest()
		{
			return tstInfo.MessageImprint.GetHashedMessage();
		}

		public byte[] GetEncoded()
		{
			return tstInfo.GetEncoded();
		}

		public TstInfo TstInfo
		{
			get { return tstInfo; }
		}
	}
}