<|start_filename|>tests/examples/hashing/sha1CryptoServicebinding.fs<|end_filename|>
module sha1CryptoServicebinding
open System.Security.Cryptography
open System.Text

let foo () =
    use sha1 = new SHA1CryptoServiceProvider()
    sha1.ComputeHash(UTF8Encoding().GetBytes("foo"))



<|start_filename|>tests/examples/hashing/sha1CryptoServicector.fs<|end_filename|>
module sha1CryptoServicector
open System.Security.Cryptography
open System.Text

let foo () =
    (new SHA1CryptoServiceProvider()).ComputeHash(UTF8Encoding().GetBytes("foo"))



<|start_filename|>tests/examples/hashing/md5CryptoServicebinding.fs<|end_filename|>
module md5CryptoServicebinding
open System.Security.Cryptography
open System.Text

let foo () =
    use md5 = new MD5CryptoServiceProvider()
    md5.ComputeHash(UTF8Encoding().GetBytes("foo"))



<|start_filename|>tests/BinaryDefense.FSharp.Analyzers.Tests/Tests.fs<|end_filename|>
module Tests

open System
open Expecto
open BinaryDefense.FSharp.Analyzers
open System.Runtime.Loader

let analyzers = [ Hashing.weakHashingAnalyzer ]

let testSeq name tests = testList name (List.ofSeq tests)


[<Tests>]
let tests =
    testSeq "Hashing Tests" <|
        testParam analyzers [
            "Check MD5.Create() binding", fun analyzers () ->
                let file = IO.Path.Combine(__SOURCE_DIRECTORY__ ,"../examples/hashing/md5create.fs")
                let results = (AnalyzerBootstrap.runProject (AnalyzerBootstrap.File file) analyzers)
                Expect.hasLength results 1 ""
                results
                |> Seq.iter(fun r ->
                    Expect.stringContains r.Message "MD5" ""
                )
            "Check MD5CryptoServiceProvider binding", fun analyzers () ->
                let file = IO.Path.Combine(__SOURCE_DIRECTORY__ ,"../examples/hashing/md5CryptoServicebinding.fs")
                let results = (AnalyzerBootstrap.runProject (AnalyzerBootstrap.File file) analyzers)
                Expect.hasLength results 4 ""
                results
                |> Seq.iter(fun r ->
                    Expect.stringContains r.Message "MD5" ""
                )
            "Check SHA1.Create() binding", fun analyzers () ->
                let file = IO.Path.Combine(__SOURCE_DIRECTORY__ ,"../examples/hashing/sha1create.fs")
                let results = (AnalyzerBootstrap.runProject (AnalyzerBootstrap.File file) analyzers)
                Expect.hasLength results 1 ""
                results
                |> Seq.iter(fun r ->
                    Expect.stringContains r.Message "SHA1" ""
                )
            "Check SHACryptoServiceProvider binding", fun analyzers () ->
                let file = IO.Path.Combine(__SOURCE_DIRECTORY__ ,"../examples/hashing/sha1CryptoServicebinding.fs")
                let results = (AnalyzerBootstrap.runProject (AnalyzerBootstrap.File file) analyzers)
                Expect.hasLength results 4 ""
                results
                |> Seq.iter(fun r ->
                    Expect.stringContains r.Message "SHA1" ""
                )
            "Check SHACryptoServiceProvider ctor", fun analyzers () ->
                let file = IO.Path.Combine(__SOURCE_DIRECTORY__ ,"../examples/hashing/sha1CryptoServicector.fs")
                let results = (AnalyzerBootstrap.runProject (AnalyzerBootstrap.File file) analyzers)
                Expect.hasLength results 1 ""
                results
                |> Seq.iter(fun r ->
                    Expect.stringContains r.Message "SHA1" ""
                )
            "Check project", fun analyzers () ->
                let file = IO.Path.Combine(__SOURCE_DIRECTORY__, "../examples/hashing/hashing.fsproj")
                let results = (AnalyzerBootstrap.runProject (AnalyzerBootstrap.Project file) analyzers)
                Expect.isGreaterThan results.Length 0 ""
            ]


<|start_filename|>tests/examples/hashing/md5create.fs<|end_filename|>
module md5create
open System.Security.Cryptography
open System.Text

let foo () =
    use md5 = MD5.Create()
    md5.ComputeHash(UTF8Encoding().GetBytes("foo"))



<|start_filename|>tests/examples/hashing/sha1create.fs<|end_filename|>
module sha1create
open System.Security.Cryptography
open System.Text

let foo () =
    use sha1 = SHA1.Create()
    sha1.ComputeHash(UTF8Encoding().GetBytes("foo"))

