diff options
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/Asn1Set.cs | 28 | ||||
-rw-r--r-- | crypto/src/asn1/BEROctetStringGenerator.cs | 39 | ||||
-rw-r--r-- | crypto/src/asn1/DerGeneralizedTime.cs | 9 | ||||
-rw-r--r-- | crypto/src/asn1/DerSequence.cs | 7 | ||||
-rw-r--r-- | crypto/src/asn1/DerSet.cs | 7 | ||||
-rw-r--r-- | crypto/src/asn1/cmp/CertResponse.cs | 3 | ||||
-rw-r--r-- | crypto/src/asn1/cmp/ErrorMsgContent.cs | 3 | ||||
-rw-r--r-- | crypto/src/asn1/crmf/CertReqMsg.cs | 3 | ||||
-rw-r--r-- | crypto/src/asn1/util/Dump.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/util/FilterStream.cs | 14 | ||||
-rw-r--r-- | crypto/src/asn1/x509/AlgorithmIdentifier.cs | 64 |
11 files changed, 97 insertions, 84 deletions
diff --git a/crypto/src/asn1/Asn1Set.cs b/crypto/src/asn1/Asn1Set.cs index 418b560fd..58e7e26f8 100644 --- a/crypto/src/asn1/Asn1Set.cs +++ b/crypto/src/asn1/Asn1Set.cs @@ -75,8 +75,8 @@ namespace Org.BouncyCastle.Asn1 * be converted. */ public static Asn1Set GetInstance( - Asn1TaggedObject obj, - bool explicitly) + Asn1TaggedObject obj, + bool explicitly) { Asn1Object inner = obj.GetObject(); @@ -85,7 +85,7 @@ namespace Org.BouncyCastle.Asn1 if (!obj.IsExplicit()) throw new ArgumentException("object implicit - explicit expected."); - return (Asn1Set) inner; + return (Asn1Set)inner; } // @@ -100,7 +100,7 @@ namespace Org.BouncyCastle.Asn1 if (inner is Asn1Set) { - return (Asn1Set) inner; + return (Asn1Set)inner; } // @@ -110,7 +110,7 @@ namespace Org.BouncyCastle.Asn1 if (inner is Asn1Sequence) { Asn1EncodableVector v = new Asn1EncodableVector(); - Asn1Sequence s = (Asn1Sequence) inner; + Asn1Sequence s = (Asn1Sequence)inner; foreach (Asn1Encodable ae in s) { @@ -149,14 +149,14 @@ namespace Org.BouncyCastle.Asn1 */ public virtual Asn1Encodable this[int index] { - get { return (Asn1Encodable) _set[index]; } + get { return (Asn1Encodable)_set[index]; } } [Obsolete("Use 'object[index]' syntax instead")] public Asn1Encodable GetObjectAt( int index) { - return this[index]; + return this[index]; } [Obsolete("Use 'Count' property instead")] @@ -207,8 +207,8 @@ namespace Org.BouncyCastle.Asn1 return ((Asn1Set)obj).Parser; // NB: Asn1OctetString implements Asn1OctetStringParser directly -// if (obj is Asn1OctetString) -// return ((Asn1OctetString)obj).Parser; + // if (obj is Asn1OctetString) + // return ((Asn1OctetString)obj).Parser; return obj; } @@ -303,12 +303,18 @@ namespace Org.BouncyCastle.Asn1 Asn1Encodable[] items = new Asn1Encodable[_set.Count]; byte[][] keys = new byte[_set.Count][]; - //List<Asn1Encodable[]> t; + for (int i = 0; i < _set.Count; ++i) + { + Asn1Encodable item = (Asn1Encodable)_set[i]; + items[i] = item; + keys[i] = item.GetEncoded(Asn1Encodable.Der); + } + Array.Sort(keys, items, new DerComparer()); for (int i = 0; i < _set.Count; ++i) { - _set[i] = sorted[i]; + _set[i] = items[i]; } #endif } diff --git a/crypto/src/asn1/BEROctetStringGenerator.cs b/crypto/src/asn1/BEROctetStringGenerator.cs index 6d7d1b66e..f34538f38 100644 --- a/crypto/src/asn1/BEROctetStringGenerator.cs +++ b/crypto/src/asn1/BEROctetStringGenerator.cs @@ -102,19 +102,32 @@ namespace Org.BouncyCastle.Asn1 } } - protected override void Dispose(bool disposing) - { - if (disposing) - { - if (_off != 0) - { - DerOctetString.Encode(_derOut, _buf, 0, _off); - } - - _gen.WriteBerEnd(); - } - base.Dispose(disposing); - } +#if PORTABLE + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (_off != 0) + { + DerOctetString.Encode(_derOut, _buf, 0, _off); + } + + _gen.WriteBerEnd(); + } + base.Dispose(disposing); + } +#else + public override void Close() + { + if (_off != 0) + { + DerOctetString.Encode(_derOut, _buf, 0, _off); + } + + _gen.WriteBerEnd(); + base.Close(); + } +#endif } } } diff --git a/crypto/src/asn1/DerGeneralizedTime.cs b/crypto/src/asn1/DerGeneralizedTime.cs index 57527f3a0..4de0feaa6 100644 --- a/crypto/src/asn1/DerGeneralizedTime.cs +++ b/crypto/src/asn1/DerGeneralizedTime.cs @@ -262,8 +262,13 @@ namespace Org.BouncyCastle.Asn1 DateTimeStyles style = DateTimeStyles.None; if (format.EndsWith("Z")) { - style = DateTimeStyles.AssumeUniversal; - + try + { + style = (DateTimeStyles)Enums.GetEnumValue(typeof(DateTimeStyles), "AssumeUniversal"); + } + catch (Exception) + { + } style |= DateTimeStyles.AdjustToUniversal; } diff --git a/crypto/src/asn1/DerSequence.cs b/crypto/src/asn1/DerSequence.cs index 1a86dc429..a76cf2882 100644 --- a/crypto/src/asn1/DerSequence.cs +++ b/crypto/src/asn1/DerSequence.cs @@ -1,6 +1,9 @@ +using System; using System.Collections; using System.IO; +using Org.BouncyCastle.Utilities; + namespace Org.BouncyCastle.Asn1 { public class DerSequence @@ -75,9 +78,9 @@ namespace Org.BouncyCastle.Asn1 dOut.WriteObject(obj); } - dOut.Dispose(); + Platform.Dispose(dOut); - byte[] bytes = bOut.ToArray(); + byte[] bytes = bOut.ToArray(); derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes); } diff --git a/crypto/src/asn1/DerSet.cs b/crypto/src/asn1/DerSet.cs index 6d3f438bd..3df1a6766 100644 --- a/crypto/src/asn1/DerSet.cs +++ b/crypto/src/asn1/DerSet.cs @@ -1,5 +1,8 @@ +using System; using System.IO; +using Org.BouncyCastle.Utilities; + namespace Org.BouncyCastle.Asn1 { /** @@ -98,9 +101,9 @@ namespace Org.BouncyCastle.Asn1 dOut.WriteObject(obj); } - dOut.Dispose(); + Platform.Dispose(dOut); - byte[] bytes = bOut.ToArray(); + byte[] bytes = bOut.ToArray(); derOut.WriteEncoded(Asn1Tags.Set | Asn1Tags.Constructed, bytes); } diff --git a/crypto/src/asn1/cmp/CertResponse.cs b/crypto/src/asn1/cmp/CertResponse.cs index 246b8ce70..80813b8b7 100644 --- a/crypto/src/asn1/cmp/CertResponse.cs +++ b/crypto/src/asn1/cmp/CertResponse.cs @@ -107,8 +107,7 @@ namespace Org.BouncyCastle.Asn1.Cmp public override Asn1Object ToAsn1Object() { Asn1EncodableVector v = new Asn1EncodableVector(certReqId, status); - v.AddOptional(certifiedKeyPair); - v.AddOptional(rspInfo); + v.AddOptional(certifiedKeyPair, rspInfo); return new DerSequence(v); } } diff --git a/crypto/src/asn1/cmp/ErrorMsgContent.cs b/crypto/src/asn1/cmp/ErrorMsgContent.cs index f4dc584ea..2d6353b65 100644 --- a/crypto/src/asn1/cmp/ErrorMsgContent.cs +++ b/crypto/src/asn1/cmp/ErrorMsgContent.cs @@ -86,8 +86,7 @@ namespace Org.BouncyCastle.Asn1.Cmp public override Asn1Object ToAsn1Object() { Asn1EncodableVector v = new Asn1EncodableVector(pkiStatusInfo); - v.AddOptional(errorCode); - v.AddOptional(errorDetails); + v.AddOptional(errorCode, errorDetails); return new DerSequence(v); } } diff --git a/crypto/src/asn1/crmf/CertReqMsg.cs b/crypto/src/asn1/crmf/CertReqMsg.cs index 2ca319a57..20fd4179a 100644 --- a/crypto/src/asn1/crmf/CertReqMsg.cs +++ b/crypto/src/asn1/crmf/CertReqMsg.cs @@ -98,8 +98,7 @@ namespace Org.BouncyCastle.Asn1.Crmf public override Asn1Object ToAsn1Object() { Asn1EncodableVector v = new Asn1EncodableVector(certReq); - v.AddOptional(popo); - v.AddOptional(regInfo); + v.AddOptional(popo, regInfo); return new DerSequence(v); } } diff --git a/crypto/src/asn1/util/Dump.cs b/crypto/src/asn1/util/Dump.cs index 99ced5836..e313fe879 100644 --- a/crypto/src/asn1/util/Dump.cs +++ b/crypto/src/asn1/util/Dump.cs @@ -2,6 +2,8 @@ using System; using System.IO; +using Org.BouncyCastle.Utilities; + namespace Org.BouncyCastle.Asn1.Utilities { public sealed class Dump @@ -21,7 +23,7 @@ namespace Org.BouncyCastle.Asn1.Utilities Console.WriteLine(Asn1Dump.DumpAsString(obj)); } - bIn.Close(); + Platform.Dispose(bIn); } } } diff --git a/crypto/src/asn1/util/FilterStream.cs b/crypto/src/asn1/util/FilterStream.cs index 3d08446cd..0c38c5b6e 100644 --- a/crypto/src/asn1/util/FilterStream.cs +++ b/crypto/src/asn1/util/FilterStream.cs @@ -1,6 +1,8 @@ using System; using System.IO; +using Org.BouncyCastle.Utilities; + namespace Org.BouncyCastle.Asn1.Utilities { [Obsolete("Use Org.BouncyCastle.Utilities.IO.FilterStream")] @@ -32,16 +34,22 @@ namespace Org.BouncyCastle.Asn1.Utilities get { return s.Position; } set { s.Position = value; } } - +#if PORTABLE protected override void Dispose(bool disposing) { if (disposing) { - s.Dispose(); + Platform.Dispose(s); } base.Dispose(disposing); } - +#else + public override void Close() + { + Platform.Dispose(s); + base.Close(); + } +#endif public override void Flush() { s.Flush(); diff --git a/crypto/src/asn1/x509/AlgorithmIdentifier.cs b/crypto/src/asn1/x509/AlgorithmIdentifier.cs index c6f4af5bf..00e7ad8bc 100644 --- a/crypto/src/asn1/x509/AlgorithmIdentifier.cs +++ b/crypto/src/asn1/x509/AlgorithmIdentifier.cs @@ -5,9 +5,8 @@ namespace Org.BouncyCastle.Asn1.X509 public class AlgorithmIdentifier : Asn1Encodable { - private readonly DerObjectIdentifier objectID; + private readonly DerObjectIdentifier algorithm; private readonly Asn1Encodable parameters; - private readonly bool parametersDefined; public static AlgorithmIdentifier GetInstance( Asn1TaggedObject obj, @@ -19,39 +18,32 @@ namespace Org.BouncyCastle.Asn1.X509 public static AlgorithmIdentifier GetInstance( object obj) { - if (obj == null || obj is AlgorithmIdentifier) - return (AlgorithmIdentifier) obj; - - // TODO: delete - if (obj is DerObjectIdentifier) - return new AlgorithmIdentifier((DerObjectIdentifier) obj); - - // TODO: delete - if (obj is string) - return new AlgorithmIdentifier((string) obj); - + if (obj == null) + return null; + if (obj is AlgorithmIdentifier) + return (AlgorithmIdentifier)obj; return new AlgorithmIdentifier(Asn1Sequence.GetInstance(obj)); } public AlgorithmIdentifier( - DerObjectIdentifier objectID) + DerObjectIdentifier algorithm) { - this.objectID = objectID; + this.algorithm = algorithm; } + [Obsolete("Use version taking a DerObjectIdentifier")] public AlgorithmIdentifier( - string objectID) + string algorithm) { - this.objectID = new DerObjectIdentifier(objectID); + this.algorithm = new DerObjectIdentifier(algorithm); } public AlgorithmIdentifier( - DerObjectIdentifier objectID, + DerObjectIdentifier algorithm, Asn1Encodable parameters) { - this.objectID = objectID; + this.algorithm = algorithm; this.parameters = parameters; - this.parametersDefined = true; } internal AlgorithmIdentifier( @@ -60,13 +52,8 @@ namespace Org.BouncyCastle.Asn1.X509 if (seq.Count < 1 || seq.Count > 2) throw new ArgumentException("Bad sequence size: " + seq.Count); - this.objectID = DerObjectIdentifier.GetInstance(seq[0]); - this.parametersDefined = (seq.Count == 2); - - if (parametersDefined) - { - this.parameters = seq[1]; - } + this.algorithm = DerObjectIdentifier.GetInstance(seq[0]); + this.parameters = seq.Count < 2 ? null : seq[1]; } /// <summary> @@ -74,18 +61,19 @@ namespace Org.BouncyCastle.Asn1.X509 /// </summary> public virtual DerObjectIdentifier Algorithm { - get { return objectID; } + get { return algorithm; } } + [Obsolete("Use 'Algorithm' property instead")] public virtual DerObjectIdentifier ObjectID { - get { return objectID; } + get { return algorithm; } } /// <summary> /// Return the parameters structure in the Parameters entry of this identifier. /// </summary> - public Asn1Encodable Parameters + public virtual Asn1Encodable Parameters { get { return parameters; } } @@ -100,20 +88,8 @@ namespace Org.BouncyCastle.Asn1.X509 */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(objectID); - - if (parametersDefined) - { - if (parameters != null) - { - v.Add(parameters); - } - else - { - v.Add(DerNull.Instance); - } - } - + Asn1EncodableVector v = new Asn1EncodableVector(algorithm); + v.AddOptional(parameters); return new DerSequence(v); } } |