Beispiel #1
0
        public override void PerformTest()
        {
//			SimpleDateFormat yyyyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
//			SimpleDateFormat yyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");

//			yyyyF.setTimeZone(new SimpleTimeZone(0,"Z"));
//			yyF.setTimeZone(new SimpleTimeZone(0,"Z"));

            for (int i = 0; i != input.Length; i++)
            {
                DerUtcTime t = new DerUtcTime(input[i]);

                if (!t.AdjustedTimeString.Equals(output[i]))
                {
                    Fail("failed conversion test " + i);
                }

//				if (!yyyyF.format(t.getAdjustedDate()).Equals(zOutput1[i]))
                if (!t.ToAdjustedDateTime().ToString(@"yyyyMMddHHmmss\Z").Equals(zOutput1[i]))
                {
                    Fail("failed date conversion test " + i);
                }

//				if (!yyF.format(t.getDate()).Equals(zOutput2[i]))
                if (!t.ToDateTime().ToString(@"yyyyMMddHHmmss\Z").Equals(zOutput2[i]))
                {
                    Fail("failed date shortened conversion test " + i);
                }
            }
        }
Beispiel #2
0
        private void AddAsn1Object(string name, DataKey root, Asn1Object obj, int level, Logger logger)
        {
            Asn1Sequence     seq      = obj as Asn1Sequence;
            Asn1Set          set      = obj as Asn1Set;
            Asn1TaggedObject tag      = obj as Asn1TaggedObject;
            string           currName = name ?? obj.GetType().Name;

            System.Diagnostics.Trace.WriteLine(String.Format("{0} {1}", currName, obj.GetType()));

            if (seq != null)
            {
                if (!Config.IgnoreSequences)
                {
                    DataKey key = new Asn1SequenceKey(currName, Config.NoVerify);

                    foreach (Asn1Object o in seq)
                    {
                        AddAsn1Object(null, key, o, level + 1, logger);
                    }

                    root.AddSubNode(key);
                }
                else
                {
                    root.AddValue(currName, obj.GetDerEncoded());
                }
            }
            else if (set != null)
            {
                if (!Config.IgnoreSets)
                {
                    DataKey key = new Asn1SetKey(currName, Config.NoVerify);

                    foreach (Asn1Object o in set)
                    {
                        AddAsn1Object(null, key, o, level + 1, logger);
                    }

                    root.AddSubNode(key);
                }
                else
                {
                    root.AddValue(currName, obj.GetDerEncoded());
                }
            }
            else if (tag != null)
            {
                if (!Config.IgnoreTaggedObjects)
                {
                    DataKey key = new Asn1TaggedObjectKey(currName, tag.TagNo, Config.NoVerify);

                    root.AddSubNode(key);

                    Asn1Object     o   = tag.GetObject();
                    DerOctetString oct = o as DerOctetString;

                    AddAsn1Object("Object", key, tag.GetObject(), level + 1, logger);

                    //if (oct != null)
                    //{
                    //    Asn1InputStream input = new Asn1InputStream(oct.GetOctetStream());

                    //    try
                    //    {
                    //        Asn1Object next = input.ReadObject();
                    //        if (next == null)
                    //        {
                    //            AddAsn1Object("Object", key, o, logger);
                    //        }
                    //        else
                    //        {
                    //            Asn1OctetStringObject newRoot = new Asn1OctetStringObject("Object");

                    //            while (next != null)
                    //            {
                    //                AddAsn1Object(next.GetType().Name, newRoot, next, logger);

                    //                next = input.ReadObject();
                    //            }

                    //            key.AddSubNode(newRoot);
                    //        }
                    //    }
                    //    catch (IOException)
                    //    {
                    //        AddAsn1Object("Object", key, o, logger);
                    //    }
                    //}
                    //else
                    //{
                    //    AddAsn1Object("Object", key, tag.GetObject(), logger);
                    //}
                }
                else
                {
                    root.AddValue(currName, obj.GetDerEncoded());
                }
            }
            else
            {
                if (!Config.NoDecode)
                {
                    DerStringBase          str  = obj as DerStringBase;
                    DerObjectIdentifier    oid  = obj as DerObjectIdentifier;
                    DerInteger             i    = obj as DerInteger;
                    DerOctetString         oct  = obj as DerOctetString;
                    DerBitString           bits = obj as DerBitString;
                    DerBoolean             boo  = obj as DerBoolean;
                    DerNull                n    = obj as DerNull;
                    DerUtcTime             time = obj as DerUtcTime;
                    DerGeneralizedTime     gt   = obj as DerGeneralizedTime;
                    DerApplicationSpecific app  = obj as DerApplicationSpecific;

                    if (oct != null)
                    {
                        root.AddValue(new Asn1OctetStringValue(currName, oct.GetOctets()));
                    }
                    else if (bits != null)
                    {
                        root.AddSubNode(new Asn1BitStringKey(currName, bits.PadBits, bits.GetBytes()));
                    }
                    else if (str != null)
                    {
                        Type stringType = typeof(Asn1StringValue <>).MakeGenericType(str.GetType());

                        root.AddValue((DataValue)Activator.CreateInstance(stringType, currName, str.GetString()));
                    }
                    else if (oid != null)
                    {
                        root.AddValue(new Asn1ObjectIdentifierValue(currName, oid.Id));
                    }
                    else if (i != null)
                    {
                        root.AddValue(new Asn1IntegerValue(currName, i.Value.ToByteArray()));
                    }
                    else if (boo != null)
                    {
                        root.AddValue(new Asn1BooleanValue(currName, boo.IsTrue));
                    }
                    else if (n != null)
                    {
                        root.AddValue(new Asn1NullValue(currName));
                    }
                    else if (time != null)
                    {
                        root.AddValue(new Asn1DateTimeValue(currName, time.ToDateTime()));
                    }
                    else if (gt != null)
                    {
                        root.AddValue(new Asn1GeneralizedTimeValue(currName, gt.ToDateTime()));
                    }
                    else if (app != null)
                    {
                        root.AddSubNode(new Asn1ApplicationSpecificValue(currName, app.ApplicationTag, app.GetContents()));
                    }
                    else
                    {
                        logger.LogError("Cannot convert type {0} to a class", obj.GetType().Name);
                        root.AddValue(currName, obj.GetDerEncoded());
                    }
                }
                else
                {
                    root.AddValue(currName, obj.GetDerEncoded());
                }
            }
        }
Beispiel #3
0
		public override void PerformTest()
		{
//			SimpleDateFormat yyyyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
//			SimpleDateFormat yyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");

//			yyyyF.setTimeZone(new SimpleTimeZone(0,"Z"));
//			yyF.setTimeZone(new SimpleTimeZone(0,"Z"));

			for (int i = 0; i != input.Length; i++)
			{
				DerUtcTime t = new DerUtcTime(input[i]);

				if (!t.AdjustedTimeString.Equals(output[i]))
				{
					Fail("failed conversion test " + i);
				}

//				if (!yyyyF.format(t.getAdjustedDate()).Equals(zOutput1[i]))
				if (!t.ToAdjustedDateTime().ToString(@"yyyyMMddHHmmss\Z").Equals(zOutput1[i]))
				{
					Fail("failed date conversion test " + i);
				}

//				if (!yyF.format(t.getDate()).Equals(zOutput2[i]))
				if (!t.ToDateTime().ToString(@"yyyyMMddHHmmss\Z").Equals(zOutput2[i]))
				{
					Fail("failed date shortened conversion test " + i);
				}
			}
		}