add all
This commit is contained in:
1 parent
4897e8d307
commit
4aca3324c9
10 files changed
+401
-17
No files matched your search
@@ -0,0 +1,6 @@
|
||||
package payload
|
||||
|
||||
/*
|
||||
This package is contains everything to create the payload.
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,57 @@
|
||||
package payload
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/cipher"
|
||||
"io"
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
type Payload interface {
|
||||
GetHash() []byte
|
||||
GetKey() []byte
|
||||
GetAlgorithm() string
|
||||
GetMode() string
|
||||
GetHashMethod() string
|
||||
GetPayloadData() io.Reader
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
type Payload struct {
|
||||
DataSource io.Reader
|
||||
Hash crypto.Hash
|
||||
Block cipher.Block
|
||||
BlockMode cipher.BlockMode
|
||||
}
|
||||
|
||||
func (this *Payload) GetHashMethod() string {
|
||||
switch this.Hash {
|
||||
case crypto.MD5:
|
||||
return "md5"
|
||||
case crypto.MD4:
|
||||
return "md4"
|
||||
case crypto.SHA1:
|
||||
return "sha1"
|
||||
case crypto.MD5SHA1:
|
||||
return "md5sha1"
|
||||
case crypto.RIPEMD160:
|
||||
return "ripemd160"
|
||||
case crypto.SHA224:
|
||||
return "sha224"
|
||||
case crypto.SHA256:
|
||||
return "sha256"
|
||||
case crypto.SHA384:
|
||||
return "sha384"
|
||||
case crypto.SHA512:
|
||||
return "sha512"
|
||||
default:
|
||||
panic("unknown hash method")
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Payload) GetPayloadData() io.Reader {
|
||||
// this.BlockMode.
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package payload
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPayloadGetHashMethod(t *testing.T) {
|
||||
p := new(Payload)
|
||||
testCases := make(map[string]crypto.Hash)
|
||||
testCases["md4"] = crypto.MD4
|
||||
testCases["md5"] = crypto.MD5
|
||||
testCases["sha1"] = crypto.SHA1
|
||||
testCases["sha224"] = crypto.SHA224
|
||||
testCases["sha256"] = crypto.SHA256
|
||||
testCases["sha384"] = crypto.SHA384
|
||||
testCases["sha512"] = crypto.SHA512
|
||||
testCases["md5sha1"] = crypto.MD5SHA1
|
||||
testCases["ripemd160"] = crypto.RIPEMD160
|
||||
for name, hashfunc := range testCases {
|
||||
p.Hash = hashfunc
|
||||
if returnedName := p.GetHashMethod(); returnedName != name {
|
||||
t.Error("bad hash name. supposed to be ", name, " but received", returnedName)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user