Add comments

This commit is contained in:
Harshavardhana
2015-03-03 01:25:45 -08:00
parent 721ec9ef5a
commit 137584d658
10 changed files with 66 additions and 77 deletions

View File

@@ -23,7 +23,6 @@ import (
"testing"
"github.com/minio-io/minio/pkg/utils/crypto/keys"
"github.com/minio-io/minio/pkg/utils/helpers"
. "gopkg.in/check.v1"
)
@@ -35,7 +34,7 @@ func Test(t *testing.T) { TestingT(t) }
func (s *MySuite) TestConfig(c *C) {
conf := Config{}
conf.configPath, _ = helpers.MakeTempTestDir()
conf.configPath, _ = ioutil.TempDir("/tmp", "minio-test-")
defer os.RemoveAll(conf.configPath)
conf.configFile = path.Join(conf.configPath, "config.json")
if _, err := os.Stat(conf.configFile); os.IsNotExist(err) {

View File

@@ -21,14 +21,17 @@ package cpu
// int has_avx2 (void);
import "C"
// CPUID instruction verification wrapper for SSE41 extensions
func HasSSE41() bool {
return int(C.has_sse41()) == 1
}
// CPUID instruction verification wrapper for AVX extensions
func HasAVX() bool {
return int(C.has_avx()) == 1
}
// CPUID instruction verification wrapper for AVX2 extensions
func HasAVX2() bool {
return int(C.has_avx2()) == 1
}

View File

@@ -55,6 +55,7 @@ func block(dig *digest, p []byte) {
}
}
// Reset digest to its default value
func (d *digest) Reset() {
d.h[0] = init0
d.h[1] = init1
@@ -75,12 +76,13 @@ func New() hash.Hash {
return d
}
func (d *digest) Size() int {
return Size
}
// Return output array byte size
func (d *digest) Size() int { return Size }
// Return blockSize
func (d *digest) BlockSize() int { return BlockSize }
// Write blocks
func (d *digest) Write(p []byte) (nn int, err error) {
nn = len(p)
d.len += uint64(nn)
@@ -104,6 +106,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
return
}
// Calculate sha512
func (d0 *digest) Sum(in []byte) []byte {
// Make a copy of d0 so that caller can keep writing and summing.
d := new(digest)
@@ -112,6 +115,7 @@ func (d0 *digest) Sum(in []byte) []byte {
return append(in, hash[:]...)
}
// internal checksum calculation, returns [Size]byte
func (d *digest) checkSum() [Size]byte {
// Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
len := d.len
@@ -153,6 +157,7 @@ func (d *digest) checkSum() [Size]byte {
// Convenience functions
// Single caller function returns [Size]byte
func Sum512(data []byte) [Size]byte {
var d digest
d.Reset()
@@ -160,6 +165,7 @@ func Sum512(data []byte) [Size]byte {
return d.checkSum()
}
// Takes in io.Reader, low memory footprint checksum
func Sum(reader io.Reader) ([]byte, error) {
h := New()
var err error
@@ -176,6 +182,7 @@ func Sum(reader io.Reader) ([]byte, error) {
return h.Sum(nil), nil
}
// Similar to 'Sum()' but returns a [Size]byte
func SumStream(reader io.Reader) ([Size]byte, error) {
var returnValue [Size]byte
sumSlice, err := Sum(reader)

View File

@@ -29,6 +29,7 @@ import (
sha512intel "github.com/minio-io/minio/pkg/utils/crypto/sha512"
)
// Intels processor accelerated sha512 implementation
func SumIntel(reader io.Reader) ([]byte, error) {
h := sha512intel.New()
var err error
@@ -45,6 +46,7 @@ func SumIntel(reader io.Reader) ([]byte, error) {
return h.Sum(nil), nil
}
// Golang default implementation
func Sum(reader io.Reader) ([]byte, error) {
k := sha512.New()
var err error

View File

@@ -72,6 +72,7 @@ func pemBlockForKey(priv interface{}) *pem.Block {
}
}
// Generate certificates using custom parameters
func (tls *Certificates) GenerateCertificates(params X509Params) error {
var rsaBits int = 2048
var priv interface{}

View File

@@ -1,50 +0,0 @@
/*
* Mini Object Storage, (C) 2014 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package helpers
import (
"io/ioutil"
"strings"
)
// Create a new temp directory
func MakeTempTestDir() (string, error) {
return ioutil.TempDir("/tmp", "minio-test-")
}
// Camelcase input string
func FirstUpper(str string) string {
return strings.ToUpper(str[0:1]) + str[1:]
}
func AppendUniqInt(slice []int, i int) []int {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}
func AppendUniqStr(slice []string, i string) []string {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}

View File

@@ -13,6 +13,7 @@ type Date struct {
Day byte
}
// Date to string output in yyyy-mm-dd format
func (d Date) String() string {
return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)
}