github - added null check for reducedHashTree on construction.
public class ArchiveTimeStamp
extends ASN1Object
{
- private AlgorithmIdentifier digestAlgorithm;
- private Attributes attributes;
- private ASN1Sequence reducedHashTree;
- private ContentInfo timeStamp;
+ private final AlgorithmIdentifier digestAlgorithm;
+ private final Attributes attributes;
+ private final ASN1Sequence reducedHashTree;
+ private final ContentInfo timeStamp;
/**
* Return an ArchiveTimestamp from the given object.
@@ -64,9 +64,13 @@ public ArchiveTimeStamp(
PartialHashtree[] reducedHashTree,
ContentInfo timeStamp)
{
- this.digestAlgorithm = digestAlgorithm;
- this.reducedHashTree = new DERSequence(reducedHashTree);
- this.timeStamp = timeStamp;
+ this(digestAlgorithm, null, reducedHashTree, timeStamp);
+ }
+
+ public ArchiveTimeStamp(
+ ContentInfo timeStamp)
+ {
+ this(null, null, null, timeStamp);
}
public ArchiveTimeStamp(
@@ -77,13 +81,14 @@ public ArchiveTimeStamp(
{
this.digestAlgorithm = digestAlgorithm;
this.attributes = attributes;
+ if (reducedHashTree != null)
+ {
this.reducedHashTree = new DERSequence(reducedHashTree);
- this.timeStamp = timeStamp;
}
-
- public ArchiveTimeStamp(
- ContentInfo timeStamp)
+ else
{
+ this.reducedHashTree = null;
+ }
this.timeStamp = timeStamp;
}
@@ -94,6 +99,9 @@ private ArchiveTimeStamp(final ASN1Sequence sequence)
throw new IllegalArgumentException("wrong sequence size in constructor: " + sequence.size());
}
+ AlgorithmIdentifier digAlg = null;
+ Attributes attrs = null;
+ ASN1Sequence rHashTree = null;
for (int i = 0; i < sequence.size() - 1; i++)
{
Object obj = sequence.getObjectAt(i);
@@ -105,13 +113,13 @@ private ArchiveTimeStamp(final ASN1Sequence sequence)
switch (taggedObject.getTagNo())
{
case 0:
- digestAlgorithm = AlgorithmIdentifier.getInstance(taggedObject, false);
+ digAlg = AlgorithmIdentifier.getInstance(taggedObject, false);
break;
case 1:
- attributes = Attributes.getInstance(taggedObject, false);
+ attrs = Attributes.getInstance(taggedObject, false);
break;
case 2:
- reducedHashTree = ASN1Sequence.getInstance(taggedObject, false);
+ rHashTree = ASN1Sequence.getInstance(taggedObject, false);
break;
default:
throw new IllegalArgumentException("invalid tag no in constructor: "
@@ -120,6 +128,9 @@ private ArchiveTimeStamp(final ASN1Sequence sequence)
}
}
+ digestAlgorithm = digAlg;
+ attributes = attrs;
+ reducedHashTree = rHashTree;
timeStamp = ContentInfo.getInstance(sequence.getObjectAt(sequence.size() - 1));
}
