Skip to content

Commit 8aa3dc5

Browse files
committed
Refactor CMSTimeStampedDataGenerator
1 parent dd56165 commit 8aa3dc5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkix/src/main/java/org/bouncycastle/tsp/cms/CMSTimeStampedDataGenerator.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public CMSTimeStampedData generate(TimeStampToken timeStamp, byte[] content) thr
3535
public CMSTimeStampedData generate(TimeStampToken timeStamp, InputStream content)
3636
throws CMSException
3737
{
38-
ByteArrayOutputStream contentOut = new ByteArrayOutputStream();
39-
38+
ASN1OctetString encContent = null;
4039
if (content != null)
4140
{
41+
ByteArrayOutputStream contentOut = new ByteArrayOutputStream();
4242
try
4343
{
4444
Streams.pipeAll(content, contentOut);
@@ -47,13 +47,11 @@ public CMSTimeStampedData generate(TimeStampToken timeStamp, InputStream content
4747
{
4848
throw new CMSException("exception encapsulating content: " + e.getMessage(), e);
4949
}
50-
}
51-
52-
ASN1OctetString encContent = null;
5350

54-
if (contentOut.size() != 0)
55-
{
56-
encContent = new BEROctetString(contentOut.toByteArray());
51+
if (contentOut.size() != 0)
52+
{
53+
encContent = new BEROctetString(contentOut.toByteArray());
54+
}
5755
}
5856

5957
TimeStampAndCRL stamp = new TimeStampAndCRL(timeStamp.toCMSSignedData().toASN1Structure());
@@ -64,8 +62,11 @@ public CMSTimeStampedData generate(TimeStampToken timeStamp, InputStream content
6462
{
6563
asn1DataUri = new DERIA5String(dataUri.toString());
6664
}
67-
68-
return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(asn1DataUri, metaData, encContent, new Evidence(new TimeStampTokenEvidence(stamp)))));
65+
66+
TimeStampedData timeStampedData = new TimeStampedData(asn1DataUri, metaData, encContent,
67+
new Evidence(new TimeStampTokenEvidence(stamp)));
68+
69+
return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, timeStampedData));
6970
}
7071
}
7172

0 commit comments

Comments
 (0)