Skip to content

Commit e8cdf2a

Browse files
committed
Refactor ContentInfo.toASN1Primitive
1 parent d20911e commit e8cdf2a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

util/src/main/java/org/bouncycastle/asn1/cms/ContentInfo.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,15 @@ public boolean isDefiniteLength()
151151
*/
152152
public ASN1Primitive toASN1Primitive()
153153
{
154-
ASN1EncodableVector v = new ASN1EncodableVector(2);
155-
156-
v.add(contentType);
157-
158-
if (content != null)
154+
if (isDefiniteLength)
159155
{
160-
if (isDefiniteLength)
161-
{
162-
v.add(new DLTaggedObject(0, content));
163-
}
164-
else
165-
{
166-
v.add(new BERTaggedObject(0, content));
167-
}
156+
return content == null
157+
? new DLSequence(contentType)
158+
: new DLSequence(contentType, new DLTaggedObject(0, content));
168159
}
169160

170-
return isDefiniteLength ? (ASN1Primitive)new DLSequence(v) : (ASN1Primitive)new BERSequence(v);
161+
return content == null
162+
? new BERSequence(contentType)
163+
: new BERSequence(contentType, new BERTaggedObject(0, content));
171164
}
172165
}

0 commit comments

Comments
 (0)