-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- create AVPRIndex.Hash module - add tests for string/byte array/file hashing - use this function exclusively in AVPRIndex and API - remove the API endpoint for direct hash creation - return http 422 if package content contains any CR characters - handle PackageContentHash creation for new packages automatically
- Loading branch information
Showing
16 changed files
with
290 additions
and
108 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace AVPRIndex | ||
|
||
open System | ||
open System.IO | ||
open System.Text | ||
open System.Security.Cryptography | ||
|
||
type Hash = | ||
|
||
// This is the function used as the first point of entry, as it is used when parsing packages that do not exist in the prioduction DB | ||
// unifying line endings is crucial to ensure that the hash is the same on all platforms | ||
|
||
/// calculates a md5 hash of the given byte array and returns it as a hex string | ||
static member hashContent (content: byte array) = | ||
let md5 = MD5.Create() | ||
content | ||
|> md5.ComputeHash | ||
|> Convert.ToHexString | ||
|
||
/// calculates a md5 hash of the given string with line endings unified to `\n` and returns it as a hex string | ||
static member hashString (content: string) = | ||
content | ||
|> fun s -> s.ReplaceLineEndings("\n") | ||
|> Encoding.UTF8.GetBytes | ||
|> Hash.hashContent | ||
|
||
/// calculates a md5 hash of the file at the given path with line endings unified to `\n` and returns it as a hex string | ||
static member hashFile (path: string) = | ||
path | ||
|> File.ReadAllText | ||
|> Hash.hashString | ||
|
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
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
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
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
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
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
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
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
Oops, something went wrong.