Esempio n. 1
0
    protected override bool Asn1Equals(Asn1Object asn1Object)
    {
        Asn1Set asn1Set = asn1Object as Asn1Set;

        if (asn1Set == null)
        {
            return(false);
        }
        if (Count != asn1Set.Count)
        {
            return(false);
        }
        IEnumerator enumerator  = GetEnumerator();
        IEnumerator enumerator2 = asn1Set.GetEnumerator();

        while (enumerator.MoveNext() && enumerator2.MoveNext())
        {
            Asn1Object asn1Object2 = GetCurrent(enumerator).ToAsn1Object();
            Asn1Object obj         = GetCurrent(enumerator2).ToAsn1Object();
            if (!asn1Object2.Equals(obj))
            {
                return(false);
            }
        }
        return(true);
    }
Esempio n. 2
0
        public override void PerformTest()
        {
            byte[] data = { 0, 1, 0, 1, 0, 0, 1 };

            Asn1Object[] values =
            {
                new BerOctetString(data),
                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,
                DerBoolean.False,
                new DerEnumerated(100),
                new DerGeneralizedTime("20070315173729Z"),
                new DerGeneralString("hello world"),
                new DerIA5String("hello"),
                new DerInteger(1000),
                DerNull.Instance,
                new DerNumericString("123456"),
                new DerObjectIdentifier("1.1.1.10000.1"),
                new DerOctetString(data),
                new DerPrintableString("hello world"),
                new DerSequence(new DerPrintableString("hello world")),
                new DerSet(new DerPrintableString("hello world")),
                new DerT61String("hello world"),
                new DerTaggedObject(0,                                 new DerPrintableString("hello world")),
                new DerUniversalString(data),
                new DerUnknownTag(true,                                                                    500,data),
                new DerUtcTime(new DateTime()),
                new DerUtf8String("hello world"),
                new DerVisibleString("hello world")
            };

            MemoryStream     bOut = new MemoryStream();
            Asn1OutputStream aOut = new Asn1OutputStream(bOut);

            for (int i = 0; i != values.Length; i++)
            {
                aOut.WriteObject(values[i]);
            }

            Asn1InputStream aIn = new Asn1InputStream(bOut.ToArray());

            for (int i = 0; i != values.Length; i++)
            {
                Asn1Object o = aIn.ReadObject();
                if (!o.Equals(values[i]))
                {
                    Fail("Failed equality test for " + o.GetType().Name);
                }

                if (o.GetHashCode() != values[i].GetHashCode())
                {
                    Fail("Failed hashCode test for " + o.GetType().Name);
                }
            }
        }
Esempio n. 3
0
        /** Parses a key and determines the key algorithm (RSA or EC) based on the ASN1 OID. */
        private static string determineKeyAlgorithm(byte[] keyBytes)
        {
            var seq = Asn1Sequence.GetInstance(keyBytes).GetEnumerator();

            seq.MoveNext();
            var seq1 = ((Asn1Sequence)seq.Current).GetEnumerator();

            seq1.MoveNext();
            Asn1Object oid = (Asn1Object)seq1.Current;

            if (oid.Equals(PkcsObjectIdentifiers.RsaEncryption))
            {
                return("RSA");
            }
            else if (oid.Equals(X9ObjectIdentifiers.IdECPublicKey))
            {
                return("EC");
            }
            else
            {
                throw new IllegalArgumentException("Unsupported key type " + oid);
            }
        }
    protected override bool Asn1Equals(Asn1Object asn1Object)
    {
        if (this == asn1Object)
        {
            return(true);
        }
        DerExternal derExternal = asn1Object as DerExternal;

        if (derExternal == null)
        {
            return(false);
        }
        if (object.Equals(directReference, derExternal.directReference) && object.Equals(indirectReference, derExternal.indirectReference) && object.Equals(dataValueDescriptor, derExternal.dataValueDescriptor))
        {
            return(externalContent.Equals(derExternal.externalContent));
        }
        return(false);
    }