summary refs log tree commit diff stats
path: root/lib/std/sha1.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/sha1.nim')
-rw-r--r--lib/std/sha1.nim41
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/std/sha1.nim b/lib/std/sha1.nim
index b74b285f8..213af4229 100644
--- a/lib/std/sha1.nim
+++ b/lib/std/sha1.nim
@@ -1,41 +1,40 @@
 #
 #
-#           The Nim Compiler
+#              Nim's Runtime Library
 #        (c) Copyright 2015 Nim Contributors
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
 #
-## **Note:** Import `std/sha1` to use this module.
-##
 ## [SHA-1 (Secure Hash Algorithm 1)](https://en.wikipedia.org/wiki/SHA-1)
 ## is a cryptographic hash function which takes an input and produces
 ## a 160-bit (20-byte) hash value known as a message digest.
 ##
-## Basic usage
-## ===========
-##
+## See also
+## ========
+## * `base64 module<base64.html>`_ for a Base64 encoder and decoder
+## * `hashes module<hashes.html>`_ for efficient computations of hash values for diverse Nim types
+## * `md5 module<md5.html>`_ for the MD5 checksum algorithm
+
 runnableExamples:
   let accessName = secureHash("John Doe")
   assert $accessName == "AE6E4D1209F17B460503904FAD297B31E9CF6362"
 
-## .. code-block::
-##   let
-##     a = secureHashFile("myFile.nim")
-##     b = parseSecureHash("10DFAEBF6BFDBC7939957068E2EFACEC4972933C")
-##
-##   if a == b:
-##     echo "Files match"
-##
-## See also
-## ========
-## * `base64 module<base64.html>`_ implements a Base64 encoder and decoder
-## * `hashes module<hashes.html>`_ for efficient computations of hash values for diverse Nim types
-## * `md5 module<md5.html>`_ implements the MD5 checksum algorithm
+runnableExamples("-r:off"):
+  let
+    a = secureHashFile("myFile.nim")
+    b = parseSecureHash("10DFAEBF6BFDBC7939957068E2EFACEC4972933C")
+  assert a == b, "files don't match"
+
+
+{.deprecated: "use command `nimble install checksums` and import `checksums/sha1` instead".}
 
 import std/strutils
 from std/endians import bigEndian32, bigEndian64
 
+when defined(nimPreviewSlimSystem):
+  import std/syncio
+
 const Sha1DigestSize = 20
 
 type
@@ -282,3 +281,7 @@ proc `==`*(a, b: SecureHash): bool =
 
   # Not a constant-time comparison, but that's acceptable in this context
   Sha1Digest(a) == Sha1Digest(b)
+
+proc isValidSha1Hash*(s: string): bool =
+  ## Checks if a string is a valid sha1 hash sum.
+  s.len == 40 and allCharsInSet(s, HexDigits)
\ No newline at end of file