Skip to content

Instantly share code, notes, and snippets.

@artur-s
Last active August 12, 2016 17:12
Show Gist options
  • Save artur-s/e9938a85923fd998da4767dabbf2fdc2 to your computer and use it in GitHub Desktop.
Save artur-s/e9938a85923fd998da4767dabbf2fdc2 to your computer and use it in GitHub Desktop.
Encoding version numbers (integers) as ETags using SHA-1
open System
open System.Security.Cryptography
let hasher = SHA1.Create()
let intToSHA1 (n:int) =
let hexString bytes =
[for b:byte in bytes -> b.ToString("x2")] |> String.concat ""
n |> (BitConverter.GetBytes >> hasher.ComputeHash >> hexString)
let versionETags =
[1;2;3;21;33;1]
|> List.map intToSHA1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment