Last active
May 16, 2016 20:55
-
-
Save ninjarobot/5b67644b792d52f8a76417a2c64088a0 to your computer and use it in GitHub Desktop.
Git object hash in FSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let calcObjHash (objData:byte array) = | |
use sha1 = new System.Security.Cryptography.SHA1Managed () | |
let pre = | |
sprintf "blob %d\000" objData.Length | |
|> System.Text.Encoding.UTF8.GetBytes | |
use ms = new System.IO.MemoryStream () | |
ms.Write (pre, 0, pre.Length) | |
ms.Write (objData, 0, objData.Length) | |
ms.Position <- 0L | |
sha1.ComputeHash (ms) | |
|> BitConverter.ToString | |
|> fun s -> s.Replace("-", "").ToLower () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment