Exemple #1
0
        internal static SafeLocalAllocHandle CopyOidsToUnmanagedMemory(OidCollection oids)
        {
            SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;

            if ((oids != null) && (oids.Count != 0))
            {
                List <string> list       = new List <string>();
                OidEnumerator enumerator = oids.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Oid current = enumerator.Current;
                    list.Add(current.Value);
                }
                IntPtr zero = IntPtr.Zero;
                int    num  = list.Count * Marshal.SizeOf(typeof(IntPtr));
                int    num2 = 0;
                foreach (string str in list)
                {
                    num2 += str.Length + 1;
                }
                invalidHandle = CAPI.LocalAlloc(0x40, new IntPtr((long)(((uint)num) + ((uint)num2))));
                zero          = new IntPtr(((long)invalidHandle.DangerousGetHandle()) + num);
                for (int i = 0; i < list.Count; i++)
                {
                    Marshal.WriteIntPtr(new IntPtr(((long)invalidHandle.DangerousGetHandle()) + (i * Marshal.SizeOf(typeof(IntPtr)))), zero);
                    byte[] bytes = Encoding.ASCII.GetBytes(list[i]);
                    Marshal.Copy(bytes, 0, zero, bytes.Length);
                    zero = new IntPtr((((long)zero) + list[i].Length) + 1L);
                }
            }
            return(invalidHandle);
        }
Exemple #2
0
        public static bool CanAuthenticateServer(X509Certificate2 certificate)
        {
            bool flag = false;

            foreach (X509Extension extension in certificate.Extensions)
            {
                if (string.Equals(extension.Oid.Value, "2.5.29.37", StringComparison.Ordinal))
                {
                    flag = true;
                    X509EnhancedKeyUsageExtension extension2 = extension as X509EnhancedKeyUsageExtension;
                    if (extension2 != null)
                    {
                        OidEnumerator enumerator = extension2.EnhancedKeyUsages.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            if (string.Equals(enumerator.Current.Value, "1.3.6.1.5.5.7.3.1", StringComparison.Ordinal))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(!flag);
        }
Exemple #3
0
 internal static System.Security.Cryptography.SafeLocalAllocHandle CopyOidsToUnmanagedMemory(OidCollection oids)
 {
     System.Security.Cryptography.SafeLocalAllocHandle invalidHandle = System.Security.Cryptography.SafeLocalAllocHandle.InvalidHandle;
     if ((oids != null) && (oids.Count != 0))
     {
         int           num        = oids.Count * Marshal.SizeOf(typeof(IntPtr));
         int           num2       = 0;
         OidEnumerator enumerator = oids.GetEnumerator();
         while (enumerator.MoveNext())
         {
             Oid current = enumerator.Current;
             num2 += current.Value.Length + 1;
         }
         invalidHandle = System.Security.Cryptography.CAPI.LocalAlloc(0x40, new IntPtr((long)((ulong)(num + num2))));
         IntPtr val = new IntPtr(((long)invalidHandle.DangerousGetHandle()) + num);
         for (int i = 0; i < oids.Count; i++)
         {
             Marshal.WriteIntPtr(new IntPtr(((long)invalidHandle.DangerousGetHandle()) + (i * Marshal.SizeOf(typeof(IntPtr)))), val);
             byte[] bytes = Encoding.ASCII.GetBytes(oids[i].Value);
             Marshal.Copy(bytes, 0, val, bytes.Length);
             val = new IntPtr((((long)val) + oids[i].Value.Length) + 1L);
         }
     }
     return(invalidHandle);
 }
Exemple #4
0
        public void Reset()
        {
            OidEnumerator enumerator = GetEnumerator();

            enumerator.MoveNext();
            Assert.IsNotNull(enumerator.Current, "Current before reset");
            enumerator.Reset();
            Assert.IsNotNull(enumerator.Current, "Current after reset");
        }
Exemple #5
0
        public void Current()
        {
            OidEnumerator enumerator = GetEnumerator();

            enumerator.MoveNext();
            Oid oid = enumerator.Current;

            Assert.IsNotNull(oid, "Current");
        }
Exemple #6
0
        public void MoveNext()
        {
            OidEnumerator enumerator = GetEnumerator();
            int           n          = 0;

            while (enumerator.MoveNext())
            {
                n++;
            }
            Assert.AreEqual(3, n, "MoveNext");
        }
Exemple #7
0
        public void Current_AfterLastElement()
        {
            OidEnumerator enumerator = GetEnumerator();

            while (enumerator.MoveNext())
            {
                ;
            }
            Oid oid = enumerator.Current;

            Assert.IsNotNull(oid, "Current_AfterLastElement");
            Assert.AreEqual("1.2", oid.Value, "Current==last");
        }
    public static void Main()
    {
        // Assign values to strings.
        string Value1       = "1.2.840.113549.1.1.1";
        string Name1        = "3DES";
        string Value2       = "1.3.6.1.4.1.311.20.2";
        string InvalidName  = "This name is not a valid name";
        string InvalidValue = "1.1.1.1.1.1.1.1";

        // Create new Oid objects using the specified values.
        // Note that the corresponding Value or Friendly Name property is automatically added to the object.
        Oid o1 = new Oid(Value1);
        Oid o2 = new Oid(Name1);

        // Create a new Oid object using the specified Value and Friendly Name properties.
        // Note that the two are not compared to determine if the Value is associated
        //  with the Friendly Name.
        Oid o3 = new Oid(Value2, InvalidName);

        //Create a new Oid object using the specified Value. Note that if the value
        //  is invalid or not known, no value is assigned to the Friendly Name property.
        Oid o4 = new Oid(InvalidValue);

        //Write out the property information of the Oid objects.
        Console.WriteLine("Oid1: Automatically assigned Friendly Name: {0}, {1}", o1.FriendlyName, o1.Value);
        Console.WriteLine("Oid2: Automatically assigned Value: {0}, {1}", o2.FriendlyName, o2.Value);
        Console.WriteLine("Oid3: Name and Value not compared: {0}, {1}", o3.FriendlyName, o3.Value);
        Console.WriteLine("Oid4: Invalid Value used: {0}, {1} {2}", o4.FriendlyName, o4.Value, Environment.NewLine);

        //Create an Oid collection and add several Oid objects.
        OidCollection oc = new OidCollection();

        oc.Add(o1);
        oc.Add(o2);
        oc.Add(o3);
        Console.WriteLine("Number of Oids in the collection: {0}", oc.Count);
        Console.WriteLine("Is synchronized: {0} {1}", oc.IsSynchronized, Environment.NewLine);

        //Create an enumerator for moving through the collection.
        OidEnumerator oe = oc.GetEnumerator();

        //You must execute a MoveNext() to get to the first item in the collection.
        oe.MoveNext();
        // Write out Oids in the collection.
        Console.WriteLine("First Oid in collection: {0},{1}", oe.Current.FriendlyName, oe.Current.Value);
        oe.MoveNext();
        Console.WriteLine("Second Oid in collection: {0},{1}", oe.Current.FriendlyName, oe.Current.Value);
        //Return index in the collection to the beginning.
        oe.Reset();
    }
Exemple #9
0
        private static SafeHGlobalHandle CopyOidsToUnmanagedMemory(OidCollection oids)
        {
            SafeHGlobalHandle invalidHandle = SafeHGlobalHandle.InvalidHandle;

            if ((oids != null) && (oids.Count != 0))
            {
                List <string> list       = new List <string>();
                OidEnumerator enumerator = oids.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Oid current = enumerator.Current;
                    list.Add(current.Value);
                }
                IntPtr zero = IntPtr.Zero;
                IntPtr ptr  = IntPtr.Zero;
                int    num  = list.Count * Marshal.SizeOf(typeof(IntPtr));
                int    num2 = 0;
                foreach (string str in list)
                {
                    num2 += str.Length + 1;
                }
                invalidHandle = SafeHGlobalHandle.AllocHGlobal((int)(num + num2));
                zero          = new IntPtr(((long)invalidHandle.DangerousGetHandle()) + num);
                for (int i = 0; i < list.Count; i++)
                {
                    Marshal.WriteIntPtr(new IntPtr(((long)invalidHandle.DangerousGetHandle()) + (i * Marshal.SizeOf(typeof(IntPtr)))), zero);
                    byte[] bytes = Encoding.ASCII.GetBytes(list[i]);
                    if (bytes.Length != list[i].Length)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("ObjectIsReadOnly")));
                    }
                    Marshal.Copy(bytes, 0, zero, bytes.Length);
                    ptr = new IntPtr(((long)zero) + bytes.Length);
                    Marshal.WriteByte(ptr, 0);
                    zero = new IntPtr((((long)zero) + list[i].Length) + 1L);
                }
            }
            return(invalidHandle);
        }
Exemple #10
0
 public void Current_BeforeFirstElement()
 {
     OidEnumerator enumerator = GetEnumerator();
     Oid           oid        = enumerator.Current;
 }