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

using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Cms;

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

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

            return new CertificateConfirmationContent(CertConfirmContent.GetInstance(pkiBody.Content), digestAlgFinder);
        }

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

        private readonly CertConfirmContent m_content;
        private readonly DefaultDigestAlgorithmIdentifierFinder m_digestAlgIDFinder;

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

        public CertificateConfirmationContent(CertConfirmContent content,
            DefaultDigestAlgorithmIdentifierFinder digestAlgFinder)
        {
            m_content = content;
            m_digestAlgIDFinder = digestAlgFinder;
        }

        public CertConfirmContent ToAsn1Structure() => m_content;

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