Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CmsSignedData: Make it so Der data can be handled #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions crypto/src/cms/CMSSignedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,22 @@ public CmsSignedData(
//
if (signedData.EncapContentInfo.Content != null)
{
this.signedContent = new CmsProcessableByteArray(
((Asn1OctetString)(signedData.EncapContentInfo.Content)).GetOctets());
if (signedData.EncapContentInfo.Content.GetType() == typeof(Asn1OctetString))
{
this.signedContent = new CmsProcessableByteArray(
((Asn1OctetString)signedData.EncapContentInfo.Content).GetOctets());
}
else
{
this.signedContent = new Pkcs7ProcessableObject(
this.signedData.EncapContentInfo.ContentType,
this.signedData.EncapContentInfo.Content);
}
}
else
{
this.signedContent = null;
}
// else
// {
// this.signedContent = null;
// }
}

/// <summary>Return the version number for this object.</summary>
Expand Down
45 changes: 45 additions & 0 deletions crypto/src/cms/Pkcs7ProcessableObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.IO;
using Org.BouncyCastle.Asn1;

namespace Org.BouncyCastle.Cms
{
public class Pkcs7ProcessableObject : CmsProcessable
{
public Asn1Object Type { get; }
public Asn1Encodable Structure { get; }

public Pkcs7ProcessableObject(Asn1Object type, Asn1Encodable structure)
{
this.Type = type;
this.Structure = structure;
}

public void Write(Stream outStream)
{
if (Structure is Asn1Sequence)
{
Asn1Sequence s = Asn1Sequence.GetInstance(Structure);

foreach (Asn1Encodable encodable in s)
{
byte[] encoded = encodable.ToAsn1Object().GetEncoded(Asn1Encodable.Der);
outStream.Write(encoded, 0, encoded.Length);
}
}
else
{
byte[] encoded = Structure.ToAsn1Object().GetEncoded(Asn1Encodable.Der);
int index = 1;

while ((encoded[index] & 0xff) > 127)
{
++index;
}

++index;

outStream.Write(encoded, index, encoded.Length - index);
}
}
}
}