mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
Implement md5c function, slower than Golang's implementation
keeping it in repo to make further improvements and also rename
minio-hash ---> crypto
This commit is contained in:
1
cmd/crypto/.gitignore
vendored
Normal file
1
cmd/crypto/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
crypto
|
||||
126
cmd/crypto/crypto-options.go
Normal file
126
cmd/crypto/crypto-options.go
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/minio/pkgs/crypto/md5"
|
||||
"github.com/minio-io/minio/pkgs/crypto/sha1"
|
||||
"github.com/minio-io/minio/pkgs/crypto/sha256"
|
||||
"github.com/minio-io/minio/pkgs/crypto/sha512"
|
||||
)
|
||||
|
||||
var Options = []cli.Command{
|
||||
Md5sum,
|
||||
Sha1sum,
|
||||
// Sha1sumFast, // not working
|
||||
Sha256sum,
|
||||
Sha512sum,
|
||||
}
|
||||
|
||||
var Md5sum = cli.Command{
|
||||
Name: "md5sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doMd5sum,
|
||||
}
|
||||
|
||||
var Sha1sum = cli.Command{
|
||||
Name: "sha1sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha1sum,
|
||||
}
|
||||
|
||||
var Sha1sumFast = cli.Command{
|
||||
Name: "sha1sum-fast",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha1sumFast,
|
||||
}
|
||||
|
||||
var Sha256sum = cli.Command{
|
||||
Name: "sha256sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha256sum,
|
||||
}
|
||||
|
||||
var Sha512sum = cli.Command{
|
||||
Name: "sha512sum",
|
||||
Usage: "",
|
||||
Description: `
|
||||
`,
|
||||
Action: doSha512sum,
|
||||
}
|
||||
|
||||
func doMd5sum(c *cli.Context) {
|
||||
hash, err := md5.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
|
||||
func doSha1sum(c *cli.Context) {
|
||||
hash, err := sha1.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
|
||||
func doSha1sumFast(c *cli.Context) {
|
||||
buffer, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
hash, err := sha1.Sha1(buffer)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var bytesBuffer bytes.Buffer
|
||||
binary.Write(&bytesBuffer, binary.LittleEndian, hash)
|
||||
fmt.Printf("%x", bytesBuffer.Bytes())
|
||||
}
|
||||
|
||||
func doSha256sum(c *cli.Context) {
|
||||
hash, err := sha256.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
|
||||
func doSha512sum(c *cli.Context) {
|
||||
hash, err := sha512.Sum(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x", hash)
|
||||
}
|
||||
31
cmd/crypto/crypto.go
Normal file
31
cmd/crypto/crypto.go
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "crypto"
|
||||
app.Usage = "calculate cryptosum on a given stream"
|
||||
app.Commands = Options
|
||||
app.Run(os.Args)
|
||||
}
|
||||
33
cmd/crypto/crypto.md
Normal file
33
cmd/crypto/crypto.md
Normal file
@@ -0,0 +1,33 @@
|
||||
% MINIO(1) Minio Manual
|
||||
% Minio community
|
||||
% December 2014
|
||||
# NAME
|
||||
crypto - calculate crypto sum on a stream
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
# DESCRIPTION
|
||||
```sh
|
||||
NAME:
|
||||
crypto - calculate cryptosum on a given stream
|
||||
|
||||
USAGE:
|
||||
crypto [global options] command [command options] [arguments...]
|
||||
|
||||
VERSION:
|
||||
0.0.0
|
||||
|
||||
COMMANDS:
|
||||
md5sum
|
||||
sha1sum
|
||||
sha256sum
|
||||
sha512sum
|
||||
help, h Shows a list of commands or help for one command
|
||||
|
||||
GLOBAL OPTIONS:
|
||||
--help, -h show help
|
||||
--version, -v print the version
|
||||
```
|
||||
# EXAMPLES
|
||||
|
||||
# AUTHORS
|
||||
Reference in New Issue
Block a user