Commits

Maxim Moiseev committed 7bbbb37

data.fs added

Comments (0)

Files changed (2)

src/VkontakteAPI/Linq2vk/Api.fs

             |> DataTools.md5
 
     module Tests =
-(*
-    md5("100172api_id=1854119fields=photo,sexformat=JSONmethod=getProfilesuids=100172v=3.0655df68ded")
-         100172api_id=1854119fields=photo,sexformat=JSONmethod=getProfilesuids=100172v=3.0655df68ded
-*)
+
         let signatureTest () =
             let query = Query.init()
                         |> Query.add "fields" "photo,sex"

src/VkontakteAPI/Linq2vk/Data.fs

+namespace Linq2vk
+
+open System
+open System.Security.Cryptography
+
+module DataTools = 
+
+    let UnixTimeStart = DateTime(1970, 1, 1)
+
+    let fromUnixtime (x:int64) = 
+         UnixTimeStart + TimeSpan.FromSeconds(x |> float)
+
+
+    let md5 (src:string) =
+        let bytes : string -> byte[] =
+            System.Text.Encoding.ASCII.GetBytes
+        let unbytes =
+            Array.map (fun (b:byte) -> b.ToString("x2"))
+                >> (fun ss -> System.String.Join("", ss))
+        let md5 = MD5.Create()        
+        src
+            |> bytes
+            |> md5.ComputeHash
+            |> unbytes
+