Commit 24c131a6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9c9b3124
...@@ -17,8 +17,12 @@ ...@@ -17,8 +17,12 @@
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options. // See https://www.nexedi.com/licensing for rationale and options.
// Package xsha1, similarly to crypto/sha1, provides SHA1 computation, but // Package xsha1 provides NEO-flavoured SHA1 sum.
// makes it a noop if requested so from environment. //
// It is the same as regular SHA1, but returns all-zeros for empty input.
//
// Besides, checksum computation can be switched to be a noop if requested so
// from environment.
package xsha1 package xsha1
import ( import (
...@@ -27,7 +31,9 @@ import ( ...@@ -27,7 +31,9 @@ import (
"os" "os"
) )
// XXX for benchmarking: how much sha1 computation takes time from latency // Skip controls and indicates whether NEOSum skips SHA1 computation.
//
// It is used for benchmarking to see how much sha1 computation takes time from latency.
var Skip bool var Skip bool
func init() { func init() {
if os.Getenv("X_NEOGO_SHA1_SKIP") == "y" { if os.Getenv("X_NEOGO_SHA1_SKIP") == "y" {
...@@ -36,23 +42,16 @@ func init() { ...@@ -36,23 +42,16 @@ func init() {
} }
} }
func Sum(b []byte) [sha1.Size]byte {
if !Skip {
return sha1.Sum(b)
}
return [sha1.Size]byte{} // all 0
}
// NEOSum returns SHA1(b) computed by NEO rules. // NEOSum returns SHA1(b) computed by NEO rules.
// //
// it is the same as regular SHA1, but returns all-zeros for empty b. // it is the same as regular SHA1, but returns all-zeros for empty b.
// https://lab.nexedi.com/nexedi/neoppod/blob/c1c26894/neo/client/app.py#L464-468 // https://lab.nexedi.com/nexedi/neoppod/blob/c1c26894/neo/client/app.py#L464-468
//
// XXX merge into Sum?
func NEOSum(b []byte) [sha1.Size]byte { func NEOSum(b []byte) [sha1.Size]byte {
if len(b) == 0 { if len(b) == 0 {
return [sha1.Size]byte{} // all 0 return [sha1.Size]byte{} // all 0
} }
return Sum(b) if !Skip {
return sha1.Sum(b)
}
return [sha1.Size]byte{} // all 0
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment