diff options
author | Peter Dettman <peter.dettman@gmail.com> | 2022-06-21 22:00:34 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@gmail.com> | 2022-06-21 22:00:34 +0700 |
commit | 62b3de2a28363f721f1bc3ecb1b9aa8990596d2d (patch) | |
tree | c8f297b54bd1f336b9c27388b4f9b01afd0047a7 | |
parent | Remove junk files (diff) | |
download | BouncyCastle.NET-ed25519-62b3de2a28363f721f1bc3ecb1b9aa8990596d2d.tar.xz |
Remove ApplicationSpecific classes
-rw-r--r-- | crypto/BouncyCastle.Android.csproj | 5 | ||||
-rw-r--r-- | crypto/BouncyCastle.csproj | 5 | ||||
-rw-r--r-- | crypto/BouncyCastle.iOS.csproj | 5 | ||||
-rw-r--r-- | crypto/crypto.csproj | 30 | ||||
-rw-r--r-- | crypto/src/asn1/ASN1StreamParser.cs | 12 | ||||
-rw-r--r-- | crypto/src/asn1/Asn1TaggedObject.cs | 88 | ||||
-rw-r--r-- | crypto/src/asn1/BERTaggedObjectParser.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/BerApplicationSpecific.cs | 47 | ||||
-rw-r--r-- | crypto/src/asn1/BerApplicationSpecificParser.cs | 19 | ||||
-rw-r--r-- | crypto/src/asn1/DLApplicationSpecific.cs | 28 | ||||
-rw-r--r-- | crypto/src/asn1/DLTaggedObjectParser.cs | 7 | ||||
-rw-r--r-- | crypto/src/asn1/DerApplicationSpecific.cs | 235 | ||||
-rw-r--r-- | crypto/src/asn1/IAsn1ApplicationSpecificParser.cs | 11 | ||||
-rw-r--r-- | crypto/src/asn1/util/Asn1Dump.cs | 4 | ||||
-rw-r--r-- | crypto/test/UnitTests.csproj | 1 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/DERApplicationSpecificTest.cs | 145 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs | 1 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/RegressionTest.cs | 1 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/TagTest.cs | 57 |
19 files changed, 31 insertions, 674 deletions
diff --git a/crypto/BouncyCastle.Android.csproj b/crypto/BouncyCastle.Android.csproj index 64b7a4c2f..28150ee85 100644 --- a/crypto/BouncyCastle.Android.csproj +++ b/crypto/BouncyCastle.Android.csproj @@ -93,8 +93,6 @@ <Compile Include="src\asn1\BERSetGenerator.cs" /> <Compile Include="src\asn1\BERSetParser.cs" /> <Compile Include="src\asn1\BERTaggedObjectParser.cs" /> - <Compile Include="src\asn1\BerApplicationSpecific.cs" /> - <Compile Include="src\asn1\BerApplicationSpecificParser.cs" /> <Compile Include="src\asn1\BerBitStringParser.cs" /> <Compile Include="src\asn1\BerOctetString.cs" /> <Compile Include="src\asn1\BerSequence.cs" /> @@ -114,7 +112,6 @@ <Compile Include="src\asn1\DERSetGenerator.cs" /> <Compile Include="src\asn1\DERSetParser.cs" /> <Compile Include="src\asn1\DefiniteLengthInputStream.cs" /> - <Compile Include="src\asn1\DerApplicationSpecific.cs" /> <Compile Include="src\asn1\DerBMPString.cs" /> <Compile Include="src\asn1\DerBitString.cs" /> <Compile Include="src\asn1\DerBoolean.cs" /> @@ -140,14 +137,12 @@ <Compile Include="src\asn1\DerUniversalString.cs" /> <Compile Include="src\asn1\DerVideotexString.cs" /> <Compile Include="src\asn1\DerVisibleString.cs" /> - <Compile Include="src\asn1\DLApplicationSpecific.cs" /> <Compile Include="src\asn1\DLBitString.cs" /> <Compile Include="src\asn1\DLBitStringParser.cs" /> <Compile Include="src\asn1\DLSequence.cs" /> <Compile Include="src\asn1\DLSet.cs" /> <Compile Include="src\asn1\DLTaggedObject.cs" /> <Compile Include="src\asn1\DLTaggedObjectParser.cs" /> - <Compile Include="src\asn1\IAsn1ApplicationSpecificParser.cs" /> <Compile Include="src\asn1\IAsn1Choice.cs" /> <Compile Include="src\asn1\IAsn1Convertible.cs" /> <Compile Include="src\asn1\IAsn1Encoding.cs" /> diff --git a/crypto/BouncyCastle.csproj b/crypto/BouncyCastle.csproj index 1580e3fc1..ae6996a96 100644 --- a/crypto/BouncyCastle.csproj +++ b/crypto/BouncyCastle.csproj @@ -87,8 +87,6 @@ <Compile Include="src\asn1\BERSetGenerator.cs" /> <Compile Include="src\asn1\BERSetParser.cs" /> <Compile Include="src\asn1\BERTaggedObjectParser.cs" /> - <Compile Include="src\asn1\BerApplicationSpecific.cs" /> - <Compile Include="src\asn1\BerApplicationSpecificParser.cs" /> <Compile Include="src\asn1\BerBitStringParser.cs" /> <Compile Include="src\asn1\BerOctetString.cs" /> <Compile Include="src\asn1\BerSequence.cs" /> @@ -108,7 +106,6 @@ <Compile Include="src\asn1\DERSetGenerator.cs" /> <Compile Include="src\asn1\DERSetParser.cs" /> <Compile Include="src\asn1\DefiniteLengthInputStream.cs" /> - <Compile Include="src\asn1\DerApplicationSpecific.cs" /> <Compile Include="src\asn1\DerBMPString.cs" /> <Compile Include="src\asn1\DerBitString.cs" /> <Compile Include="src\asn1\DerBoolean.cs" /> @@ -134,14 +131,12 @@ <Compile Include="src\asn1\DerUniversalString.cs" /> <Compile Include="src\asn1\DerVideotexString.cs" /> <Compile Include="src\asn1\DerVisibleString.cs" /> - <Compile Include="src\asn1\DLApplicationSpecific.cs" /> <Compile Include="src\asn1\DLBitString.cs" /> <Compile Include="src\asn1\DLBitStringParser.cs" /> <Compile Include="src\asn1\DLSequence.cs" /> <Compile Include="src\asn1\DLSet.cs" /> <Compile Include="src\asn1\DLTaggedObject.cs" /> <Compile Include="src\asn1\DLTaggedObjectParser.cs" /> - <Compile Include="src\asn1\IAsn1ApplicationSpecificParser.cs" /> <Compile Include="src\asn1\IAsn1Choice.cs" /> <Compile Include="src\asn1\IAsn1Convertible.cs" /> <Compile Include="src\asn1\IAsn1Encoding.cs" /> diff --git a/crypto/BouncyCastle.iOS.csproj b/crypto/BouncyCastle.iOS.csproj index a3210b4db..2ccc627f4 100644 --- a/crypto/BouncyCastle.iOS.csproj +++ b/crypto/BouncyCastle.iOS.csproj @@ -88,8 +88,6 @@ <Compile Include="src\asn1\BERSetGenerator.cs" /> <Compile Include="src\asn1\BERSetParser.cs" /> <Compile Include="src\asn1\BERTaggedObjectParser.cs" /> - <Compile Include="src\asn1\BerApplicationSpecific.cs" /> - <Compile Include="src\asn1\BerApplicationSpecificParser.cs" /> <Compile Include="src\asn1\BerBitStringParser.cs" /> <Compile Include="src\asn1\BerOctetString.cs" /> <Compile Include="src\asn1\BerSequence.cs" /> @@ -109,7 +107,6 @@ <Compile Include="src\asn1\DERSetGenerator.cs" /> <Compile Include="src\asn1\DERSetParser.cs" /> <Compile Include="src\asn1\DefiniteLengthInputStream.cs" /> - <Compile Include="src\asn1\DerApplicationSpecific.cs" /> <Compile Include="src\asn1\DerBMPString.cs" /> <Compile Include="src\asn1\DerBitString.cs" /> <Compile Include="src\asn1\DerBoolean.cs" /> @@ -135,14 +132,12 @@ <Compile Include="src\asn1\DerUniversalString.cs" /> <Compile Include="src\asn1\DerVideotexString.cs" /> <Compile Include="src\asn1\DerVisibleString.cs" /> - <Compile Include="src\asn1\DLApplicationSpecific.cs" /> <Compile Include="src\asn1\DLBitString.cs" /> <Compile Include="src\asn1\DLBitStringParser.cs" /> <Compile Include="src\asn1\DLSequence.cs" /> <Compile Include="src\asn1\DLSet.cs" /> <Compile Include="src\asn1\DLTaggedObject.cs" /> <Compile Include="src\asn1\DLTaggedObjectParser.cs" /> - <Compile Include="src\asn1\IAsn1ApplicationSpecificParser.cs" /> <Compile Include="src\asn1\IAsn1Choice.cs" /> <Compile Include="src\asn1\IAsn1Convertible.cs" /> <Compile Include="src\asn1\IAsn1Encoding.cs" /> diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj index 212fd78e9..3fd0a5bda 100644 --- a/crypto/crypto.csproj +++ b/crypto/crypto.csproj @@ -279,16 +279,6 @@ BuildAction = "Compile" /> <File - RelPath = "src\asn1\BERApplicationSpecific.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "src\asn1\BERApplicationSpecificParser.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "src\asn1\BERBitString.cs" SubType = "Code" BuildAction = "Compile" @@ -389,11 +379,6 @@ BuildAction = "Compile" /> <File - RelPath = "src\asn1\DERApplicationSpecific.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "src\asn1\DERBitString.cs" SubType = "Code" BuildAction = "Compile" @@ -559,11 +544,6 @@ BuildAction = "Compile" /> <File - RelPath = "src\asn1\DLApplicationSpecific.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "src\asn1\DLBitString.cs" SubType = "Code" BuildAction = "Compile" @@ -594,11 +574,6 @@ BuildAction = "Compile" /> <File - RelPath = "src\asn1\IAsn1ApplicationSpecificParser.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "src\asn1\IAsn1Choice.cs" SubType = "Code" BuildAction = "Compile" @@ -12554,11 +12529,6 @@ BuildAction = "Compile" /> <File - RelPath = "test\src\asn1\test\DERApplicationSpecificTest.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "test\src\asn1\test\DERUTF8StringTest.cs" SubType = "Code" BuildAction = "Compile" diff --git a/crypto/src/asn1/ASN1StreamParser.cs b/crypto/src/asn1/ASN1StreamParser.cs index 3281310c0..f805f68a5 100644 --- a/crypto/src/asn1/ASN1StreamParser.cs +++ b/crypto/src/asn1/ASN1StreamParser.cs @@ -71,12 +71,7 @@ namespace Org.BouncyCastle.Asn1 int tagClass = tagHdr & Asn1Tags.Private; if (0 != tagClass) - { - if (Asn1Tags.Application == tagClass) - return new BerApplicationSpecificParser(tagNo, sp); - return new BerTaggedObjectParser(tagClass, tagNo, sp); - } return sp.ParseImplicitConstructedIL(tagNo); } @@ -94,13 +89,6 @@ namespace Org.BouncyCastle.Asn1 { bool isConstructed = (tagHdr & Asn1Tags.Constructed) != 0; - // TODO[asn1] Special handling can be removed once ASN1ApplicationSpecific types removed. - if (Asn1Tags.Application == tagClass) - { - // This cast is ensuring the current user-expected return type. - return (DLApplicationSpecific)sp.LoadTaggedDL(tagClass, tagNo, isConstructed); - } - return new DLTaggedObjectParser(tagClass, tagNo, isConstructed, sp); } diff --git a/crypto/src/asn1/Asn1TaggedObject.cs b/crypto/src/asn1/Asn1TaggedObject.cs index 3bc339c83..8882cdcb7 100644 --- a/crypto/src/asn1/Asn1TaggedObject.cs +++ b/crypto/src/asn1/Asn1TaggedObject.cs @@ -93,9 +93,6 @@ namespace Org.BouncyCastle.Asn1 protected override bool Asn1Equals(Asn1Object asn1Object) { - if (asn1Object is DerApplicationSpecific) - return asn1Object.CallAsn1Equals(this); - Asn1TaggedObject that = asn1Object as Asn1TaggedObject; if (null == that || this.tagNo != that.tagNo || this.tagClass != that.tagClass) return false; @@ -194,61 +191,6 @@ namespace Org.BouncyCastle.Asn1 } /** - * Return the contents of this object as a byte[] - * - * @return the encoded contents of the object. - */ - // TODO Need this public if/when DerApplicationSpecific extends Asn1TaggedObject - internal byte[] GetContents() - { - try - { - byte[] baseEncoding = obj.GetEncoded(Asn1Encoding); - if (IsExplicit()) - return baseEncoding; - - MemoryStream input = new MemoryStream(baseEncoding, false); - int tag = input.ReadByte(); - Asn1InputStream.ReadTagNumber(input, tag); - int length = Asn1InputStream.ReadLength(input, (int)(input.Length - input.Position), false); - int remaining = (int)(input.Length - input.Position); - - // For indefinite form, account for end-of-contents octets - int contentsLength = length < 0 ? remaining - 2 : remaining; - if (contentsLength < 0) - throw new InvalidOperationException("failed to get contents"); - - byte[] contents = new byte[contentsLength]; - Array.Copy(baseEncoding, baseEncoding.Length - remaining, contents, 0, contentsLength); - return contents; - } - catch (IOException e) - { - throw new InvalidOperationException("failed to get contents", e); - } - } - - internal bool IsConstructed() - { - switch (explicitness) - { - case DeclaredImplicit: - { - Asn1Object baseObject = obj.ToAsn1Object(); - if (baseObject is Asn1Sequence || baseObject is Asn1Set) - return true; - - Asn1TaggedObject baseTagged = baseObject as Asn1TaggedObject; - return null != baseTagged && baseTagged.IsConstructed(); - } - case ParsedImplicit: - return obj is Asn1Sequence; - default: - return true; - } - } - - /** * return whatever was following the tag. * <p> * Note: tagged objects are generally context dependent if you're @@ -420,49 +362,25 @@ namespace Org.BouncyCastle.Asn1 { bool maybeExplicit = (contentsElements.Count == 1); - Asn1TaggedObject taggedObject = maybeExplicit + return maybeExplicit ? new DLTaggedObject(ParsedExplicit, tagClass, tagNo, contentsElements[0]) : new DLTaggedObject(ParsedImplicit, tagClass, tagNo, DLSequence.FromVector(contentsElements)); - - switch (tagClass) - { - case Asn1Tags.Application: - return new DLApplicationSpecific(taggedObject); - default: - return taggedObject; - } } internal static Asn1Object CreateConstructedIL(int tagClass, int tagNo, Asn1EncodableVector contentsElements) { bool maybeExplicit = (contentsElements.Count == 1); - Asn1TaggedObject taggedObject = maybeExplicit + return maybeExplicit ? new BerTaggedObject(ParsedExplicit, tagClass, tagNo, contentsElements[0]) : new BerTaggedObject(ParsedImplicit, tagClass, tagNo, BerSequence.FromVector(contentsElements)); - - switch (tagClass) - { - case Asn1Tags.Application: - return new BerApplicationSpecific(taggedObject); - default: - return taggedObject; - } } internal static Asn1Object CreatePrimitive(int tagClass, int tagNo, byte[] contentsOctets) { // Note: !CONSTRUCTED => IMPLICIT - Asn1TaggedObject taggedObject = new DLTaggedObject(ParsedImplicit, tagClass, tagNo, + return new DLTaggedObject(ParsedImplicit, tagClass, tagNo, new DerOctetString(contentsOctets)); - - switch (tagClass) - { - case Asn1Tags.Application: - return new DLApplicationSpecific(taggedObject); - default: - return taggedObject; - } } private static Asn1TaggedObject CheckedCast(Asn1Object asn1Object) diff --git a/crypto/src/asn1/BERTaggedObjectParser.cs b/crypto/src/asn1/BERTaggedObjectParser.cs index 8fee8977f..522e0d22b 100644 --- a/crypto/src/asn1/BERTaggedObjectParser.cs +++ b/crypto/src/asn1/BERTaggedObjectParser.cs @@ -71,10 +71,6 @@ namespace Org.BouncyCastle.Asn1 public virtual Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo) { - // TODO[asn1] Special handling can be removed once ASN1ApplicationSpecificParser types removed. - if (Asn1Tags.Application == baseTagClass) - return new BerApplicationSpecificParser(baseTagNo, m_parser); - return new BerTaggedObjectParser(baseTagClass, baseTagNo, m_parser); } diff --git a/crypto/src/asn1/BerApplicationSpecific.cs b/crypto/src/asn1/BerApplicationSpecific.cs deleted file mode 100644 index 2a874984f..000000000 --- a/crypto/src/asn1/BerApplicationSpecific.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -namespace Org.BouncyCastle.Asn1 -{ - public class BerApplicationSpecific - : DerApplicationSpecific - { - /** - * Create an application specific object with an explicit tag - * - * @param tagNo the tag number for this object. - * @param baseEncodable the object to be contained. - */ - public BerApplicationSpecific(int tagNo, Asn1Encodable baseEncodable) - : this(true, tagNo, baseEncodable) - { - } - - /** - * Create an application specific object with the tagging style given by the value of explicit. - * - * @param explicit true if the object is explicitly tagged. - * @param tagNo the tag number for this object. - * @param baseEncodable the object to be contained. - */ - public BerApplicationSpecific(bool isExplicit, int tagNo, Asn1Encodable baseEncodable) - : base(new BerTaggedObject(isExplicit, Asn1Tags.Application, tagNo, baseEncodable)) - { - } - - /** - * Create an application specific object which is marked as constructed - * - * @param tagNo the tag number for this object. - * @param contentsElements the objects making up the application specific object. - */ - public BerApplicationSpecific(int tagNo, Asn1EncodableVector contentsElements) - : base(new BerTaggedObject(false, Asn1Tags.Application, tagNo, BerSequence.FromVector(contentsElements))) - { - } - - internal BerApplicationSpecific(Asn1TaggedObject taggedObject) - : base(taggedObject) - { - } - } -} diff --git a/crypto/src/asn1/BerApplicationSpecificParser.cs b/crypto/src/asn1/BerApplicationSpecificParser.cs deleted file mode 100644 index 343dc5d68..000000000 --- a/crypto/src/asn1/BerApplicationSpecificParser.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Org.BouncyCastle.Asn1 -{ - internal class BerApplicationSpecificParser - : BerTaggedObjectParser, IAsn1ApplicationSpecificParser - { - internal BerApplicationSpecificParser(int tagNo, Asn1StreamParser parser) - : base(Asn1Tags.Application, tagNo, parser) - { - } - - public IAsn1Convertible ReadObject() - { - // NOTE: No way to say you're looking for an implicitly-tagged object via IAsn1ApplicationSpecificParser - return ParseExplicitBaseObject(); - } - } -} diff --git a/crypto/src/asn1/DLApplicationSpecific.cs b/crypto/src/asn1/DLApplicationSpecific.cs deleted file mode 100644 index 8fffcf65b..000000000 --- a/crypto/src/asn1/DLApplicationSpecific.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace Org.BouncyCastle.Asn1 -{ - internal class DLApplicationSpecific - : DerApplicationSpecific - { - internal DLApplicationSpecific(int tagNo, Asn1Encodable baseEncodable) - : this(true, tagNo, baseEncodable) - { - } - - internal DLApplicationSpecific(bool isExplicit, int tagNo, Asn1Encodable baseEncodable) - : base(new DLTaggedObject(isExplicit, Asn1Tags.Application, tagNo, baseEncodable)) - { - } - - internal DLApplicationSpecific(int tagNo, Asn1EncodableVector contentsElements) - : base(new DLTaggedObject(false, Asn1Tags.Application, tagNo, DLSequence.FromVector(contentsElements))) - { - } - - internal DLApplicationSpecific(Asn1TaggedObject taggedObject) - : base(taggedObject) - { - } - } -} diff --git a/crypto/src/asn1/DLTaggedObjectParser.cs b/crypto/src/asn1/DLTaggedObjectParser.cs index 307a6342a..3a89a69cd 100644 --- a/crypto/src/asn1/DLTaggedObjectParser.cs +++ b/crypto/src/asn1/DLTaggedObjectParser.cs @@ -55,13 +55,6 @@ namespace Org.BouncyCastle.Asn1 public override Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo) { - // TODO[asn1] Special handling can be removed once ASN1ApplicationSpecificParser types removed. - if (Asn1Tags.Application == baseTagClass) - { - // This cast is ensuring the current user-expected return type. - return (DLApplicationSpecific)m_parser.LoadTaggedDL(baseTagClass, baseTagNo, m_constructed); - } - return new DLTaggedObjectParser(baseTagClass, baseTagNo, m_constructed, m_parser); } diff --git a/crypto/src/asn1/DerApplicationSpecific.cs b/crypto/src/asn1/DerApplicationSpecific.cs deleted file mode 100644 index d474034ed..000000000 --- a/crypto/src/asn1/DerApplicationSpecific.cs +++ /dev/null @@ -1,235 +0,0 @@ -using System; -using System.IO; - -using Org.BouncyCastle.Utilities; - -namespace Org.BouncyCastle.Asn1 -{ - /** - * Base class for an application specific object - */ - public class DerApplicationSpecific - : Asn1Object, IAsn1ApplicationSpecificParser - { - public static DerApplicationSpecific GetInstance(object obj) - { - if (obj == null || obj is DerApplicationSpecific) - { - return (DerApplicationSpecific)obj; - } - else if (obj is byte[]) - { - try - { - return GetInstance(FromByteArray((byte[])obj)); - } - catch (IOException e) - { - throw new ArgumentException("failed to construct application-specific from byte[]: " + e.Message); - } - } - - throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj"); - } - - internal readonly Asn1TaggedObject m_taggedObject; - - /** - * Create an application specific object from the passed in data. This will assume - * the data does not represent a constructed object. - * - * @param tagNo the tag number for this object. - * @param contentsOctets the encoding of the object's body. - */ - public DerApplicationSpecific(int tagNo, byte[] contentsOctets) - : this(new DerTaggedObject(false, Asn1Tags.Application, tagNo, new DerOctetString(contentsOctets))) - { - } - - /** - * Create an application specific object with a tagging of explicit/constructed. - * - * @param tag the tag number for this object. - * @param object the object to be contained. - */ - public DerApplicationSpecific(int tag, Asn1Encodable baseEncodable) - : this(true, tag, baseEncodable) - { - } - - /** - * Create an application specific object with the tagging style given by the value of explicit. - * - * @param explicit true if the object is explicitly tagged. - * @param tagNo the tag number for this object. - * @param baseEncodable the object to be contained. - */ - public DerApplicationSpecific(bool isExplicit, int tagNo, Asn1Encodable baseEncodable) - : this(new DerTaggedObject(isExplicit, Asn1Tags.Application, tagNo, baseEncodable)) - { - } - - /** - * Create an application specific object which is marked as constructed - * - * @param tagNo the tag number for this object. - * @param contentsElements the objects making up the application specific object. - */ - public DerApplicationSpecific(int tagNo, Asn1EncodableVector contentsElements) - : this(new DerTaggedObject(false, Asn1Tags.Application, tagNo, DerSequence.FromVector(contentsElements))) - { - } - - internal DerApplicationSpecific(Asn1TaggedObject taggedObject) - //: base(taggedObject.explicitness, CheckTagClass(taggedObject.tagClass), taggedObject.tagNo, - // taggedObject.obj) - { - CheckTagClass(taggedObject.TagClass); - - this.m_taggedObject = taggedObject; - } - - public int ApplicationTag - { - get { return m_taggedObject.TagNo; } - } - - [Obsolete("Will be removed")] - public byte[] GetContents() - { - return m_taggedObject.GetContents(); - } - - public Asn1Object GetEnclosedObject() - { - return m_taggedObject.GetBaseObject().ToAsn1Object(); - } - - [Obsolete("Use GetEnclosedObject instead")] - public Asn1Object GetObject() - { - return GetEnclosedObject(); - } - - public Asn1Object GetObject(int tagNo) - { - return m_taggedObject.GetBaseUniversal(false, tagNo); - } - - public IAsn1Convertible GetObjectParser(int tag, bool isExplicit) - { - throw new Asn1Exception("this method only valid for CONTEXT_SPECIFIC tags"); - } - - public IAsn1Convertible ParseBaseUniversal(bool declaredExplicit, int baseTagNo) - { - return m_taggedObject.ParseBaseUniversal(declaredExplicit, baseTagNo); - } - - public IAsn1Convertible ParseExplicitBaseObject() - { - return TaggedObject.ParseExplicitBaseObject(); - } - - public Asn1TaggedObjectParser ParseExplicitBaseTagged() - { - return m_taggedObject.ParseExplicitBaseTagged(); - } - - public Asn1TaggedObjectParser ParseImplicitBaseTagged(int baseTagClass, int baseTagNo) - { - return m_taggedObject.ParseImplicitBaseTagged(baseTagClass, baseTagNo); - } - - public bool HasApplicationTag(int tagNo) - { - return m_taggedObject.HasTag(Asn1Tags.Application, tagNo); - } - - public bool HasContextTag(int tagNo) - { - return false; - } - - public bool HasTag(int tagClass, int tagNo) - { - return m_taggedObject.HasTag(tagClass, tagNo); - } - - [Obsolete("Will be removed")] - public bool IsConstructed() - { - return m_taggedObject.IsConstructed(); - } - - public IAsn1Convertible ReadObject() - { - // NOTE: No way to say you're looking for an implicitly-tagged object via IAsn1ApplicationSpecificParser - return ParseExplicitBaseObject(); - } - - public int TagClass - { - get { return m_taggedObject.TagClass; } - } - - public int TagNo - { - get { return m_taggedObject.TagNo; } - } - - /** - * DerApplicationSpecific uses an internal Asn1TaggedObject for the - * implementation, and will soon be deprecated in favour of using - * Asn1TaggedObject with a tag class of {@link Asn1Tags#Application}. This method - * lets you get the internal Asn1TaggedObject so that client code can begin the - * migration. - */ - public Asn1TaggedObject TaggedObject - { - get { return m_taggedObject; } - } - - protected override bool Asn1Equals(Asn1Object asn1Object) - { - Asn1TaggedObject that; - if (asn1Object is DerApplicationSpecific) - { - that = ((DerApplicationSpecific)asn1Object).m_taggedObject; - } - else if (asn1Object is Asn1TaggedObject) - { - that = (Asn1TaggedObject)asn1Object; - } - else - { - return false; - } - - return m_taggedObject.Equals(that); - } - - protected override int Asn1GetHashCode() - { - return m_taggedObject.CallAsn1GetHashCode(); - } - - internal override IAsn1Encoding GetEncoding(int encoding) - { - return m_taggedObject.GetEncoding(encoding); - } - - internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo) - { - return m_taggedObject.GetEncodingImplicit(encoding, tagClass, tagNo); - } - - private static int CheckTagClass(int tagClass) - { - if (Asn1Tags.Application != tagClass) - throw new ArgumentException(); - - return tagClass; - } - } -} diff --git a/crypto/src/asn1/IAsn1ApplicationSpecificParser.cs b/crypto/src/asn1/IAsn1ApplicationSpecificParser.cs deleted file mode 100644 index f8dec2791..000000000 --- a/crypto/src/asn1/IAsn1ApplicationSpecificParser.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Org.BouncyCastle.Asn1 -{ - [Obsolete("Test for Asn1TaggedObjectParser with TagClass of Asn1Tags.Application instead")] - public interface IAsn1ApplicationSpecificParser - : Asn1TaggedObjectParser - { - IAsn1Convertible ReadObject(); - } -} diff --git a/crypto/src/asn1/util/Asn1Dump.cs b/crypto/src/asn1/util/Asn1Dump.cs index 0ba5c394f..406511a72 100644 --- a/crypto/src/asn1/util/Asn1Dump.cs +++ b/crypto/src/asn1/util/Asn1Dump.cs @@ -81,10 +81,6 @@ namespace Org.BouncyCastle.Asn1.Utilities AsString(elementsIndent, verbose, set[i].ToAsn1Object(), buf); } } - else if (obj is DerApplicationSpecific) - { - AsString(indent, verbose, ((DerApplicationSpecific)obj).TaggedObject, buf); - } else if (obj is Asn1TaggedObject) { buf.Append(indent); diff --git a/crypto/test/UnitTests.csproj b/crypto/test/UnitTests.csproj index 8fd93a962..b7c889e70 100644 --- a/crypto/test/UnitTests.csproj +++ b/crypto/test/UnitTests.csproj @@ -70,7 +70,6 @@ <Compile Include="src\asn1\test\CommitmentTypeQualifierUnitTest.cs" /> <Compile Include="src\asn1\test\ContentHintsUnitTest.cs" /> <Compile Include="src\asn1\test\CscaMasterListTest.cs" /> - <Compile Include="src\asn1\test\DERApplicationSpecificTest.cs" /> <Compile Include="src\asn1\test\DERUTF8StringTest.cs" /> <Compile Include="src\asn1\test\DataGroupHashUnitTest.cs" /> <Compile Include="src\asn1\test\DeclarationOfMajorityUnitTest.cs" /> diff --git a/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs b/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs deleted file mode 100644 index e505acd9d..000000000 --- a/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.Text; - -using NUnit.Framework; - -using Org.BouncyCastle.Utilities; -using Org.BouncyCastle.Utilities.Encoders; -using Org.BouncyCastle.Utilities.Test; - -namespace Org.BouncyCastle.Asn1.Tests -{ - [TestFixture] - public class DerApplicationSpecificTest - : SimpleTest - { - private static readonly byte[] impData = Hex.Decode("430109"); - - private static readonly byte[] certData = Hex.Decode( - "7F218201897F4E8201495F290100420E44454356434145504153533030317F49" - + "81FD060A04007F00070202020202811CD7C134AA264366862A18302575D1D787" - + "B09F075797DA89F57EC8C0FF821C68A5E62CA9CE6C1C299803A6C1530B514E18" - + "2AD8B0042A59CAD29F43831C2580F63CCFE44138870713B1A92369E33E2135D2" - + "66DBB372386C400B8439040D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C" - + "1E6EFDEE12C07D58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D376" - + "1402CD851CD7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A793" - + "9F863904393EE8E06DB6C7F528F8B4260B49AA93309824D92CDB1807E5437EE2" - + "E26E29B73A7111530FA86B350037CB9415E153704394463797139E148701015F" - + "200E44454356434145504153533030317F4C0E060904007F0007030102015301" - + "C15F25060007000400015F24060009000400015F37384CCF25C59F3612EEE188" - + "75F6C5F2E2D21F0395683B532A26E4C189B71EFE659C3F26E0EB9AEAE9986310" - + "7F9B0DADA16414FFA204516AEE2B"); - - private static readonly byte[] sampleData = Hex.Decode( - "613280020780a106060456000104a203020101a305a103020101be80288006025101020109a080b2800a01000000000000000000"); - - public override string Name - { - get { return "DerApplicationSpecific"; } - } - - private void TestTaggedObject() - { - // boolean explicit, int tagNo, ASN1Encodable obj - bool isExplicit = false; - - // Type1 ::= VisibleString - DerVisibleString type1 = new DerVisibleString("Jones"); - if (!Arrays.AreEqual(Hex.Decode("1A054A6F6E6573"), type1.GetEncoded())) - { - Fail("ERROR: expected value doesn't match!"); - } - - // Type2 ::= [APPLICATION 3] IMPLICIT Type1 - isExplicit = false; - DerApplicationSpecific type2 = new DerApplicationSpecific(isExplicit, 3, type1); - // type2.isConstructed() - if (!Arrays.AreEqual(Hex.Decode("43054A6F6E6573"), type2.GetEncoded())) - { - Fail("ERROR: expected value doesn't match!"); - } - - // Type3 ::= [2] Type2 - isExplicit = true; - DerTaggedObject type3 = new DerTaggedObject(isExplicit, 2, type2); - if (!Arrays.AreEqual(Hex.Decode("A20743054A6F6E6573"), type3.GetEncoded())) - { - Fail("ERROR: expected value doesn't match!"); - } - - // Type4 ::= [APPLICATION 7] IMPLICIT Type3 - isExplicit = false; - DerApplicationSpecific type4 = new DerApplicationSpecific(isExplicit, 7, type3); - if (!Arrays.AreEqual(Hex.Decode("670743054A6F6E6573"), type4.GetEncoded())) - { - Fail("ERROR: expected value doesn't match!"); - } - - // Type5 ::= [2] IMPLICIT Type2 - isExplicit = false; - DerTaggedObject type5 = new DerTaggedObject(isExplicit, 2, type2); - // type5.isConstructed() - if (!Arrays.AreEqual(Hex.Decode("82054A6F6E6573"), type5.GetEncoded())) - { - Fail("ERROR: expected value doesn't match!"); - } - } - - public override void PerformTest() - { - TestTaggedObject(); - - DerApplicationSpecific appSpec = (DerApplicationSpecific)Asn1Object.FromByteArray(sampleData); - - if (1 != appSpec.ApplicationTag) - { - Fail("wrong tag detected"); - } - - DerInteger val = new DerInteger(9); - - DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val); - - if (!AreEqual(impData, tagged.GetEncoded())) - { - Fail("implicit encoding failed"); - } - - DerInteger recVal = (DerInteger) tagged.GetObject(Asn1Tags.Integer); - - if (!val.Equals(recVal)) - { - Fail("implicit read back failed"); - } - - DerApplicationSpecific certObj = (DerApplicationSpecific) - Asn1Object.FromByteArray(certData); - - if (!certObj.IsConstructed() || certObj.ApplicationTag != 33) - { - Fail("parsing of certificate data failed"); - } - - byte[] encoded = certObj.GetDerEncoded(); - - if (!Arrays.AreEqual(certData, encoded)) - { - Fail("re-encoding of certificate data failed"); - } - } - - public static void Main( - string[] args) - { - RunTest(new DerApplicationSpecificTest()); - } - - [Test] - public void TestFunction() - { - string resultText = Perform().ToString(); - - Assert.AreEqual(Name + ": Okay", resultText); - } - } -} diff --git a/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs b/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs index 396268f4b..a296a806e 100644 --- a/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs +++ b/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs @@ -23,7 +23,6 @@ namespace Org.BouncyCastle.Asn1.Tests new BerSequence(new DerPrintableString("hello world")), new BerSet(new DerPrintableString("hello world")), new BerTaggedObject(0, new DerPrintableString("hello world")), - new DerApplicationSpecific(0, data), new DerBitString(data), new DerBmpString("hello world"), DerBoolean.True, diff --git a/crypto/test/src/asn1/test/RegressionTest.cs b/crypto/test/src/asn1/test/RegressionTest.cs index 7bc10b079..fe612ba1b 100644 --- a/crypto/test/src/asn1/test/RegressionTest.cs +++ b/crypto/test/src/asn1/test/RegressionTest.cs @@ -24,7 +24,6 @@ namespace Org.BouncyCastle.Asn1.Tests new CscaMasterListTest(), new DataGroupHashUnitTest(), new DeclarationOfMajorityUnitTest(), - new DerApplicationSpecificTest(), new DerUtf8StringTest(), new EncryptedPrivateKeyInfoTest(), new EqualsAndHashCodeTest(), diff --git a/crypto/test/src/asn1/test/TagTest.cs b/crypto/test/src/asn1/test/TagTest.cs index fd6995c44..44b4fd4f1 100644 --- a/crypto/test/src/asn1/test/TagTest.cs +++ b/crypto/test/src/asn1/test/TagTest.cs @@ -38,54 +38,54 @@ namespace Org.BouncyCastle.Asn1.Tests { Asn1InputStream aIn = new Asn1InputStream(longTagged); - DerApplicationSpecific app = (DerApplicationSpecific)aIn.ReadObject(); - - aIn = new Asn1InputStream(app.GetContents()); - - app = (DerApplicationSpecific)aIn.ReadObject(); + Asn1TaggedObject app = (Asn1TaggedObject)aIn.ReadObject(); + if (!app.HasTag(Asn1Tags.Application, 5)) + { + Fail("unexpected tag value found - not 5"); + } - aIn = new Asn1InputStream(app.GetContents()); + app = app.GetExplicitBaseTagged(); + if (!app.HasTag(Asn1Tags.Application, 19)) + { + Fail("unexpected tag value found - not 19"); + } - Asn1TaggedObject tagged = (Asn1TaggedObject)aIn.ReadObject(); + Asn1Sequence seq = (Asn1Sequence)app.GetBaseUniversal(false, Asn1Tags.Sequence); - if (tagged.TagNo != 32) + Asn1TaggedObject tagged = (Asn1TaggedObject)seq[0]; + if (!tagged.HasContextTag(32)) { Fail("unexpected tag value found - not 32"); } - tagged = (Asn1TaggedObject) Asn1Object.FromByteArray(tagged.GetEncoded()); - - if (tagged.TagNo != 32) + tagged = (Asn1TaggedObject)Asn1Object.FromByteArray(tagged.GetEncoded()); + if (!tagged.HasContextTag(32)) { Fail("unexpected tag value found on recode - not 32"); } - tagged = (Asn1TaggedObject) aIn.ReadObject(); - - if (tagged.TagNo != 33) + tagged = (Asn1TaggedObject)seq[1]; + if (!tagged.HasContextTag(33)) { Fail("unexpected tag value found - not 33"); } tagged = (Asn1TaggedObject) Asn1Object.FromByteArray(tagged.GetEncoded()); - - if (tagged.TagNo != 33) + if (!tagged.HasContextTag(33)) { Fail("unexpected tag value found on recode - not 33"); } aIn = new Asn1InputStream(longAppSpecificTag); - app = (DerApplicationSpecific)aIn.ReadObject(); - - if (app.ApplicationTag != 97) + app = (Asn1TaggedObject)aIn.ReadObject(); + if (!app.HasTag(Asn1Tags.Application, 97)) { Fail("incorrect tag number read"); } - app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded()); - - if (app.ApplicationTag != 97) + app = (Asn1TaggedObject)Asn1Object.FromByteArray(app.GetEncoded()); + if (!app.HasTag(Asn1Tags.Application, 97)) { Fail("incorrect tag number read on recode"); } @@ -94,17 +94,16 @@ namespace Org.BouncyCastle.Asn1.Tests for (int i = 0; i < 100; ++i) { int testTag = (sr.NextInt() & int.MaxValue) >> sr.Next(26); - app = new DerApplicationSpecific(testTag, new byte[]{ 1 }); - app = (DerApplicationSpecific)Asn1Object.FromByteArray(app.GetEncoded()); + app = new DerTaggedObject(false, Asn1Tags.Application, testTag, new DerOctetString(new byte[]{ 1 })); + app = (Asn1TaggedObject)Asn1Object.FromByteArray(app.GetEncoded()); - if (app.ApplicationTag != testTag) + if (!app.HasTag(Asn1Tags.Application, testTag)) { - Fail("incorrect tag number read on recode (random test value: " + testTag + ")"); - } + Fail("incorrect tag number read on recode (random test value: " + testTag + ")"); + } } - tagged = new DerTaggedObject(false, 34, new DerTaggedObject(true, 1000, new DerInteger(1))); - + tagged = new DerTaggedObject(false, 34, new DerTaggedObject(true, 1000, new DerInteger(1))); if (!AreEqual(taggedInteger, tagged.GetEncoded())) { Fail("incorrect encoding for implicit explicit tagged integer"); |