summary refs log tree commit diff
path: root/crypto/src/cmp/CertificateConfirmationContent.cs
blob: edd4a28ed9eff9c7a598f7646db70bc8e450db22 (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
using System;

using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Operators.Utilities;

namespace Org.BouncyCastle.Cmp
{
    public class CertificateConfirmationContent
    {
        public static CertificateConfirmationContent FromPkiBody(PkiBody pkiBody) =>
            FromPkiBody(pkiBody, DefaultDigestAlgorithmFinder.Instance);

        public static CertificateConfirmationContent FromPkiBody(PkiBody pkiBody,
            IDigestAlgorithmFinder digestAlgorithmFinder)
        {
            if (!IsCertificateConfirmationContent(pkiBody.Type))
                throw new ArgumentException("content of PKIBody wrong type: " + pkiBody.Type);

            var content = CertConfirmContent.GetInstance(pkiBody.Content);

            return new CertificateConfirmationContent(content, digestAlgorithmFinder);
        }

        public static bool IsCertificateConfirmationContent(int bodyType) => PkiBody.TYPE_CERT_CONFIRM == bodyType;

        private readonly CertConfirmContent m_content;
        private readonly IDigestAlgorithmFinder m_digestAlgorithmFinder;

        public CertificateConfirmationContent(CertConfirmContent content)
            : this(content, DefaultDigestAlgorithmFinder.Instance)
        {
        }

        [Obsolete("Use constructor taking 'IDigestAlgorithmFinder' instead")]
        public CertificateConfirmationContent(CertConfirmContent content,
            Org.BouncyCastle.Cms.DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
            : this(content, (IDigestAlgorithmFinder)digestAlgFinder)
        {
        }

        public CertificateConfirmationContent(CertConfirmContent content, IDigestAlgorithmFinder digestAlgorithmFinder)
        {
            m_content = content;
            m_digestAlgorithmFinder = digestAlgorithmFinder;
        }

        public CertConfirmContent ToAsn1Structure() => m_content;

        public CertificateStatus[] GetStatusMessages() => Array.ConvertAll(m_content.ToCertStatusArray(),
            element => new CertificateStatus(m_digestAlgorithmFinder, element));
    }
}