예제 #1
0
파일: wolfSSL.cs 프로젝트: dgarske/wolfssl
        /// <summary>
        /// Create a new ssl structure
        /// </summary>
        /// <param name="ctx">structure to create ssl structure from</param>
        /// <returns>pointer to ssl structure</returns>
        public static IntPtr new_ssl(IntPtr ctx)
        {
            if (ctx == IntPtr.Zero)
                return IntPtr.Zero;

            try
            {
                ctx_handles io;
                IntPtr local_ctx = unwrap(ctx);
                if (local_ctx == IntPtr.Zero)
                {
                    log(ERROR_LOG, "new_ssl error");
                    return IntPtr.Zero;
                }

                io = new ctx_handles();
                io.set_ctx(wolfSSL_new(local_ctx));

                /* check if null */
                if (io.get_ctx() == IntPtr.Zero)
                {
                    return IntPtr.Zero;
                }

                /* keep memory pinned to be able to refrence by address */
                return GCHandle.ToIntPtr(GCHandle.Alloc(io, GCHandleType.Pinned));
            }
            catch (Exception e)
            {
                log(ERROR_LOG, e.ToString());
                return IntPtr.Zero;
            }
        }
예제 #2
0
파일: wolfSSL.cs 프로젝트: dgarske/wolfssl
        /// <summary>
        /// Create a new CTX structure
        /// </summary>
        /// <param name="method">method to use such as TLSv1.2</param>
        /// <returns>pointer to CTX structure</returns>
        public static IntPtr CTX_new(IntPtr method)
        {
            try
            {
                IntPtr ctx = wolfSSL_CTX_new(method);
                if (ctx == IntPtr.Zero)
                    return ctx;

                ctx_handles io = new ctx_handles();
                io.set_ctx(ctx);

                CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSLCbIORecv);
                io.set_receive(GCHandle.Alloc(recv));
                wolfSSL_SetIORecv(ctx, recv);

                CallbackIOSend_delegate send = new CallbackIOSend_delegate(wolfssl.wolfSSLCbIOSend);
                io.set_send(GCHandle.Alloc(send));
                wolfSSL_SetIOSend(ctx, send);

                /* keep memory pinned */
                return GCHandle.ToIntPtr(GCHandle.Alloc(io, GCHandleType.Pinned));
            }
            catch (Exception e)
            {
                log(ERROR_LOG, "ctx_new error " + e.ToString());
                return IntPtr.Zero;
            }
        }