diff options
author | Adam Strzelecki <ono@java.pl> | 2015-06-09 22:55:29 +0200 |
---|---|---|
committer | Adam Strzelecki <ono@java.pl> | 2015-06-09 22:57:44 +0200 |
commit | 4e14c0ad9fc790a8a8d22ddcd2a28ed90322c4e7 (patch) | |
tree | 104fe17537e2ceacebfd0e8d8936bad5f512ad80 /compiler | |
parent | 54c863d6ae36faa9ba14fa2a5c34ea38d4be6efe (diff) | |
download | Nim-4e14c0ad9fc790a8a8d22ddcd2a28ed90322c4e7.tar.gz |
securehash: SHA1 -> Sha1 according to style guide
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/securehash.nim | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/compiler/securehash.nim b/compiler/securehash.nim index ad15c2e8f..8ac6acb0e 100644 --- a/compiler/securehash.nim +++ b/compiler/securehash.nim @@ -10,28 +10,28 @@ import strutils, unsigned -const SHA1DigestSize = 20 +const Sha1DigestSize = 20 type - SHA1Digest = array[0 .. SHA1DigestSize-1, uint8] - SecureHash* = distinct SHA1Digest + Sha1Digest = array[0 .. Sha1DigestSize-1, uint8] + SecureHash* = distinct Sha1Digest -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.. <SHA1DigestSize: - 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: @@ -68,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] @@ -139,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 @@ -191,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 .. SHA1DigestSize-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) |