summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ast.nim2
-rw-r--r--compiler/cgen.nim2
-rw-r--r--compiler/extccomp.nim3
-rw-r--r--compiler/jsgen.nim2
-rw-r--r--compiler/modules.nim2
-rw-r--r--compiler/rodread.nim2
-rw-r--r--compiler/rodwrite.nim3
-rw-r--r--compiler/securehash.nim (renamed from compiler/secure_hash.nim)42
8 files changed, 26 insertions, 32 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index dc190fd7f..36d29e06a 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -10,7 +10,7 @@
 # abstract syntax tree + symbol table
 
 import
-  msgs, hashes, nversion, options, strutils, secure_hash, ropes, idents, lists,
+  msgs, hashes, nversion, options, strutils, securehash, ropes, idents, lists,
   intsets, idgen
 
 type
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 03aa0b4d4..390150cf7 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -11,7 +11,7 @@
 
 import
   ast, astalgo, hashes, trees, platform, magicsys, extccomp, options, intsets,
-  nversion, nimsets, msgs, secure_hash, bitsets, idents, lists, types,
+  nversion, nimsets, msgs, securehash, bitsets, idents, lists, types,
   ccgutils, os, ropes, math, passes, rodread, wordrecg, treetab, cgmeth,
   condsyms, rodutils, renderer, idgen, cgendata, ccgmerge, semfold, aliases,
   lowerings, semparallel
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index 2ddb98aba..38427b367 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -13,7 +13,8 @@
 # nim files.
 
 import
-  lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, secure_hash
+  lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs,
+  securehash
 
 type
   TSystemCC* = enum
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 346a52cfc..1f82306d2 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -31,7 +31,7 @@ implements the required case distinction.
 
 import
   ast, astalgo, strutils, hashes, trees, platform, magicsys, extccomp, options,
-  nversion, nimsets, msgs, secure_hash, bitsets, idents, lists, types, os,
+  nversion, nimsets, msgs, securehash, bitsets, idents, lists, types, os,
   times, ropes, math, passes, ccgutils, wordrecg, renderer, rodread, rodutils,
   intsets, cgmeth, lowerings
 
diff --git a/compiler/modules.nim b/compiler/modules.nim
index 0573b91f8..6cb14c091 100644
--- a/compiler/modules.nim
+++ b/compiler/modules.nim
@@ -10,7 +10,7 @@
 ## implements the module handling
 
 import
-  ast, astalgo, magicsys, secure_hash, rodread, msgs, cgendata, sigmatch, options,
+  ast, astalgo, magicsys, securehash, rodread, msgs, cgendata, sigmatch, options,
   idents, os, lexer, idgen, passes, syntaxes, llstream
 
 type
diff --git a/compiler/rodread.nim b/compiler/rodread.nim
index 27cb96ca1..dad7d111e 100644
--- a/compiler/rodread.nim
+++ b/compiler/rodread.nim
@@ -90,7 +90,7 @@
 
 import 
   os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms, 
-  ropes, idents, secure_hash, idgen, types, rodutils, memfiles
+  ropes, idents, securehash, idgen, types, rodutils, memfiles
 
 type 
   TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
diff --git a/compiler/rodwrite.nim b/compiler/rodwrite.nim
index 3454b9ade..737387597 100644
--- a/compiler/rodwrite.nim
+++ b/compiler/rodwrite.nim
@@ -13,7 +13,8 @@
 
 import 
   intsets, os, options, strutils, nversion, ast, astalgo, msgs, platform,
-  condsyms, ropes, idents, secure_hash, rodread, passes, importer, idgen, rodutils
+  condsyms, ropes, idents, securehash, rodread, passes, importer, idgen,
+  rodutils
 
 # implementation
 
diff --git a/compiler/secure_hash.nim b/compiler/securehash.nim
index 3383f23a2..8ac6acb0e 100644
--- a/compiler/secure_hash.nim
+++ b/compiler/securehash.nim
@@ -10,36 +10,28 @@
 import
   strutils, unsigned
 
-const sha_digest_size = 20
+const Sha1DigestSize = 20
 
 type
-  SHA1Digest = array[0 .. sha_digest_size-1, uint8]
-  SecureHash* = distinct SHA1Digest
+  Sha1Digest = array[0 .. Sha1DigestSize-1, uint8]
+  SecureHash* = distinct Sha1Digest
 
-const emptySecureHash = SecureHash([
-  0u8, 0, 0, 0,
-  0, 0, 0, 0,
-  0, 0, 0, 0,
-  0, 0, 0, 0,
-  0, 0, 0, 0,
-])
-
-proc sha1(src: string) : SHA1Digest
+proc sha1(src: string) : Sha1Digest
 
 proc secureHash*(str: string): SecureHash = SecureHash(sha1(str))
 proc secureHashFile*(filename: string): SecureHash = secureHash(readFile(filename))
 proc `$`*(self: SecureHash): string =
   result = ""
-  for v in SHA1Digest(self):
+  for v in Sha1Digest(self):
     result.add(toHex(int(v), 2))
 
 proc parseSecureHash*(hash: string): SecureHash =
-  for i in 0.. <sha_digest_size:
-    SHA1Digest(result)[i] = uint8(parseHexInt(hash[i*2] & hash[i*2 + 1]))
+  for i in 0.. <Sha1DigestSize:
+    Sha1Digest(result)[i] = uint8(parseHexInt(hash[i*2] & hash[i*2 + 1]))
 
 proc `==`*(a, b: SecureHash): bool =
   # Not a constant-time comparison, but that's acceptable in this context
-  SHA1Digest(a) == SHA1Digest(b)
+  Sha1Digest(a) == Sha1Digest(b)
 
 
 when isMainModule:
@@ -76,20 +68,20 @@ when isMainModule:
 # Ported to Nim by Erik O'Leary
 
 type
-  SHA1State = array[0 .. 5-1, uint32]
-  SHA1Buffer = array[0 .. 80-1, uint32]
+  Sha1State = array[0 .. 5-1, uint32]
+  Sha1Buffer = array[0 .. 80-1, uint32]
 
-template clearBuffer(w: SHA1Buffer, len = 16) =
+template clearBuffer(w: Sha1Buffer, len = 16) =
   zeroMem(addr(w), len * sizeof(uint32))
 
-proc init(result: var SHA1State) =
+proc init(result: var Sha1State) =
   result[0] = 0x67452301'u32
   result[1] = 0xefcdab89'u32
   result[2] = 0x98badcfe'u32
   result[3] = 0x10325476'u32
   result[4] = 0xc3d2e1f0'u32
 
-proc innerHash(state: var SHA1State, w: var SHA1Buffer) =
+proc innerHash(state: var Sha1State, w: var Sha1Buffer) =
   var
     a = state[0]
     b = state[1]
@@ -147,11 +139,11 @@ proc innerHash(state: var SHA1State, w: var SHA1Buffer) =
 
 template computeInternal(src: expr): stmt {.immediate.} =
   #Initialize state
-  var state: SHA1State
+  var state: Sha1State
   init(state)
 
   #Create w buffer
-  var w: SHA1Buffer
+  var w: Sha1Buffer
 
   #Loop through all complete 64byte blocks.
   let byteLen         = src.len
@@ -199,9 +191,9 @@ template computeInternal(src: expr): stmt {.immediate.} =
 
   # Store hash in result pointer, and make sure we get in in the correct order
   # on both endian models.
-  for i in 0 .. sha_digest_size-1:
+  for i in 0 .. Sha1DigestSize-1:
     result[i] = uint8((int(state[i shr 2]) shr ((3-(i and 3)) * 8)) and 255)
 
-proc sha1(src: string) : SHA1Digest =
+proc sha1(src: string) : Sha1Digest =
   ## Calculate SHA1 from input string
   computeInternal(src)