예제 #1
0
        private void ComputeHashValueOrString(IntPtr info, bool hashValue)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);

            byte[] buffer = null;
            if (arguments.Length > 0)
            {
                buffer = (arguments[0] as NSJSUInt8Array)?.Buffer;
                if (buffer == null)
                {
                    string s = (arguments[0] as NSJSString).Value;
                    if (s != null)
                    {
                        Encoding encoding = NSJSEncoding.DefaultEncoding;
                        if (arguments.Length > 1)
                        {
                            encoding = NSJSEncoding.GetEncoding(arguments[1] as NSJSObject);
                        }
                        buffer = encoding.GetBytes(s);
                    }
                }
            }
            if (buffer == null)
            {
                Throwable.ArgumentNullException(arguments.VirtualMachine);
            }
            else
            {
                try
                {
                    using (HASHAlgorithm hash = New())
                    {
                        buffer = hash.ComputeHash(buffer);
                        if (hashValue)
                        {
                            arguments.SetReturnValue(buffer);
                        }
                        else
                        {
                            string s = string.Empty;
                            for (int i = 0; i < buffer.Length; i++)
                            {
                                s += buffer[i].ToString("X2");
                            }
                            arguments.SetReturnValue(s);
                        }
                    }
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
            }
        }
 internal static object CreatePrivate(global::System.IO.Stream requestStream, global::System.Security.Cryptography.HashAlgorithm hashAlgorithm, long contentLength, global::System.Text.Encoding encoding, string multipartBoundary, global::Memba.FileUpload.UploadData uploadData)
 {
     object[] args = new object[] {
         requestStream,
         hashAlgorithm,
         contentLength,
         encoding,
         multipartBoundary,
         uploadData
     };
     Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject priv_obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject("Memba.FileUpload.XP", "Memba.FileUpload.RequestFilter", new System.Type[] {
         typeof(global::System.IO.Stream),
         typeof(global::System.Security.Cryptography.HashAlgorithm),
         typeof(long),
         typeof(global::System.Text.Encoding),
         typeof(string),
         typeof(global::Memba.FileUpload.UploadData)
     }, args);
     return(priv_obj.Target);
 }