diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-02-13 20:56:44 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-02-13 20:56:44 +0700 |
commit | ce8a94ae634fd0a7d8ce60443f8834608d42c919 (patch) | |
tree | 42c06401426d561e4fc984debbe0ae810277905b /crypto/src/asn1/pkcs | |
parent | Update release notes (diff) | |
download | BouncyCastle.NET-ed25519-ce8a94ae634fd0a7d8ce60443f8834608d42c919.tar.xz |
ASN.1 updates from bc-java
Diffstat (limited to 'crypto/src/asn1/pkcs')
-rw-r--r-- | crypto/src/asn1/pkcs/AuthenticatedSafe.cs | 38 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/Pfx.cs | 30 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/SafeBag.cs | 18 |
3 files changed, 66 insertions, 20 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); } } } diff --git a/crypto/src/asn1/pkcs/Pfx.cs b/crypto/src/asn1/pkcs/Pfx.cs index 4f958a070..3aec8ed0f 100644 --- a/crypto/src/asn1/pkcs/Pfx.cs +++ b/crypto/src/asn1/pkcs/Pfx.cs @@ -11,29 +11,35 @@ namespace Org.BouncyCastle.Asn1.Pkcs public class Pfx : Asn1Encodable { - private ContentInfo contentInfo; - private MacData macData; + public static Pfx GetInstance(object obj) + { + if (obj is Pfx) + return (Pfx)obj; + if (obj == null) + return null; + return new Pfx(Asn1Sequence.GetInstance(obj)); + } + + private readonly ContentInfo contentInfo; + private readonly MacData macData; + [Obsolete("Use 'GetInstance' instead")] public Pfx( Asn1Sequence seq) { - BigInteger version = ((DerInteger) seq[0]).Value; - if (version.IntValue != 3) - { + DerInteger version = DerInteger.GetInstance(seq[0]); + if (version.IntValueExact != 3) throw new ArgumentException("wrong version for PFX PDU"); - } - contentInfo = ContentInfo.GetInstance(seq[1]); + this.contentInfo = ContentInfo.GetInstance(seq[1]); - if (seq.Count == 3) + if (seq.Count == 3) { - macData = MacData.GetInstance(seq[2]); + this.macData = MacData.GetInstance(seq[2]); } } - public Pfx( - ContentInfo contentInfo, - MacData macData) + public Pfx(ContentInfo contentInfo, MacData macData) { this.contentInfo = contentInfo; this.macData = macData; diff --git a/crypto/src/asn1/pkcs/SafeBag.cs b/crypto/src/asn1/pkcs/SafeBag.cs index ea1ce951e..7951d4892 100644 --- a/crypto/src/asn1/pkcs/SafeBag.cs +++ b/crypto/src/asn1/pkcs/SafeBag.cs @@ -1,3 +1,5 @@ +using System; + using Org.BouncyCastle.Asn1; namespace Org.BouncyCastle.Asn1.Pkcs @@ -5,6 +7,15 @@ namespace Org.BouncyCastle.Asn1.Pkcs public class SafeBag : Asn1Encodable { + public static SafeBag GetInstance(object obj) + { + if (obj is SafeBag) + return (SafeBag)obj; + if (obj == null) + return null; + return new SafeBag(Asn1Sequence.GetInstance(obj)); + } + private readonly DerObjectIdentifier bagID; private readonly Asn1Object bagValue; private readonly Asn1Set bagAttributes; @@ -28,14 +39,15 @@ namespace Org.BouncyCastle.Asn1.Pkcs this.bagAttributes = bagAttributes; } + [Obsolete("Use 'GetInstance' instead")] public SafeBag( Asn1Sequence seq) { - this.bagID = (DerObjectIdentifier) seq[0]; - this.bagValue = ((DerTaggedObject) seq[1]).GetObject(); + this.bagID = (DerObjectIdentifier)seq[0]; + this.bagValue = ((DerTaggedObject)seq[1]).GetObject(); if (seq.Count == 3) { - this.bagAttributes = (Asn1Set) seq[2]; + this.bagAttributes = (Asn1Set)seq[2]; } } |