Skip to content

Commit

Permalink
Remove isValidSha1Hash procedure
Browse files Browse the repository at this point in the history
`isValidSha1Hash` procedure is removed from Nimble. The analogous
procedure from `std/sha1` is used instead.

Related to #127
  • Loading branch information
bobeff committed Apr 24, 2021
1 parent a3b7ed0 commit 545a789
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions src/nimblepkg/sha1hashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ proc invalidSha1Hash(value: string): ref InvalidSha1HashError =
result = newNimbleError[InvalidSha1HashError](
&"The string '{value}' does not represent a valid sha1 hash value.")

proc isValidSha1Hash(value: string): bool =
## Checks whether given string is a valid sha1 hash value. Only lower case
## hexadecimal digits are accepted.
if value.len != 40:
# A valid sha1 hash should be 40 characters long string.
return false
for c in value:
if c notin {'0' .. '9', 'a'..'f'}:
# It also should contain only lower case hexadecimal digits.
return false
return true

proc initSha1Hash*(value: string): Sha1Hash =
## Creates a new `Sha1Hash` object from a string by making all latin letters
## lower case and validating the transformed value. In the case the supplied
Expand All @@ -63,14 +51,6 @@ proc initFromJson*(dst: var Sha1Hash, jsonNode: JsonNode,
when isMainModule:
import unittest

test "validate sha1":
check not isValidSha1Hash("")
check not isValidSha1Hash("9")
check not isValidSha1Hash("99345ce680cd3e48acdb9ab4212e4bd9bf9358g7")
check not isValidSha1Hash("99345ce680cd3e48acdb9ab4212e4bd9bf9358b")
check not isValidSha1Hash("99345CE680CD3E48ACDB9AB4212E4BD9BF9358B7")
check isValidSha1Hash("99345ce680cd3e48acdb9ab4212e4bd9bf9358b7")

test "init sha1":
check initSha1Hash("") == notSetSha1Hash
expect InvalidSha1HashError: discard initSha1Hash("9")
Expand Down

0 comments on commit 545a789

Please sign in to comment.