diff options
Diffstat (limited to 'crypto/src/asn1/pkcs/AuthenticatedSafe.cs')
-rw-r--r-- | crypto/src/asn1/pkcs/AuthenticatedSafe.cs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/crypto/src/asn1/pkcs/AuthenticatedSafe.cs b/crypto/src/asn1/pkcs/AuthenticatedSafe.cs index f3dabb89c..6a112d9df 100644 --- a/crypto/src/asn1/pkcs/AuthenticatedSafe.cs +++ b/crypto/src/asn1/pkcs/AuthenticatedSafe.cs @@ -1,3 +1,5 @@ +using System; + using Org.BouncyCastle.Asn1; namespace Org.BouncyCastle.Asn1.Pkcs @@ -5,33 +7,59 @@ namespace Org.BouncyCastle.Asn1.Pkcs public class AuthenticatedSafe : Asn1Encodable { + private static ContentInfo[] Copy(ContentInfo[] info) + { + return (ContentInfo[])info.Clone(); + } + + public static AuthenticatedSafe GetInstance(object obj) + { + if (obj is AuthenticatedSafe) + return (AuthenticatedSafe)obj; + if (obj == null) + return null; + return new AuthenticatedSafe(Asn1Sequence.GetInstance(obj)); + } + private readonly ContentInfo[] info; + private readonly bool isBer; + [Obsolete("Use 'GetInstance' instead")] public AuthenticatedSafe( Asn1Sequence seq) { info = new ContentInfo[seq.Count]; - for (int i = 0; i != info.Length; i++) + for (int i = 0; i != info.Length; i++) { info[i] = ContentInfo.GetInstance(seq[i]); } + + isBer = seq is BerSequence; } public AuthenticatedSafe( ContentInfo[] info) { - this.info = (ContentInfo[]) info.Clone(); + this.info = Copy(info); + this.isBer = true; } public ContentInfo[] GetContentInfo() { - return (ContentInfo[]) info.Clone(); + return Copy(info); } - public override Asn1Object ToAsn1Object() + public override Asn1Object ToAsn1Object() { - return new BerSequence(info); + if (isBer) + { + return new BerSequence(info); + } + + // TODO bc-java uses DL sequence + //return new DLSequence(info); + return new DerSequence(info); } } } |