summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/cmp/ProtectedPkiMessageBuilder.cs6
-rw-r--r--crypto/test/src/cmp/test/ProtectedMessageTest.cs10
2 files changed, 12 insertions, 4 deletions
diff --git a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
index 8ce0d48dc..5939e92df 100644
--- a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
+++ b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
@@ -90,6 +90,9 @@ namespace Org.BouncyCastle.Cmp
 
         public ProtectedPkiMessage Build(ISignatureFactory signatureFactory)
         {
+            if (null == body)
+                throw new InvalidOperationException("body must be set before building");
+
             IStreamCalculator calculator = signatureFactory.CreateCalculator();
 
             if (!(signatureFactory.AlgorithmDetails is AlgorithmIdentifier))
@@ -105,6 +108,9 @@ namespace Org.BouncyCastle.Cmp
 
         public ProtectedPkiMessage Build(IMacFactory factory)
         {
+            if (null == body)
+                throw new InvalidOperationException("body must be set before building");
+
             IStreamCalculator calculator = factory.CreateCalculator();
             FinalizeHeader((AlgorithmIdentifier)factory.AlgorithmDetails);
             PkiHeader header = hdrBuilBuilder.Build();
diff --git a/crypto/test/src/cmp/test/ProtectedMessageTest.cs b/crypto/test/src/cmp/test/ProtectedMessageTest.cs
index 70bf670da..034463310 100644
--- a/crypto/test/src/cmp/test/ProtectedMessageTest.cs
+++ b/crypto/test/src/cmp/test/ProtectedMessageTest.cs
@@ -220,8 +220,9 @@ namespace Org.BouncyCastle.Cmp.Tests
             GeneralName sender = new GeneralName(new X509Name("CN=Sender"));
             GeneralName recipient = new GeneralName(new X509Name("CN=Recip"));
 
-            ProtectedPkiMessageBuilder msgBuilder = new ProtectedPkiMessageBuilder(sender, recipient);
-            msgBuilder.AddCmpCertificate(cert);
+            ProtectedPkiMessageBuilder msgBuilder = new ProtectedPkiMessageBuilder(sender, recipient)
+                .SetBody(new PkiBody(PkiBody.TYPE_INIT_REP, CertRepMessage.GetInstance(new DerSequence(new DerSequence()))))
+                .AddCmpCertificate(cert);
 
             ISignatureFactory sigFact = new Asn1SignatureFactory("MD5WithRSA", rsaKeyPair.Private);
 
@@ -254,8 +255,9 @@ namespace Org.BouncyCastle.Cmp.Tests
             GeneralName sender = new GeneralName(new X509Name("CN=Sender"));
             GeneralName recipient = new GeneralName(new X509Name("CN=Recip"));
 
-            ProtectedPkiMessageBuilder msgBuilder = new ProtectedPkiMessageBuilder(sender, recipient);
-            msgBuilder.AddCmpCertificate(cert);
+            ProtectedPkiMessageBuilder msgBuilder = new ProtectedPkiMessageBuilder(sender, recipient)
+                .SetBody(new PkiBody(PkiBody.TYPE_INIT_REP, CertRepMessage.GetInstance(new DerSequence(new DerSequence()))))
+                .AddCmpCertificate(cert);
 
             //
             // Default instance.