my computer will still die soon
This commit is contained in:
1 parent
e80f2601ab
commit
52a13b9cab
7 files changed
+62
-6
No files matched your search
+5
-3
@@ -47,9 +47,11 @@ func (this Block) CreateBlock(rd io.Reader) (cipher.Block, []byte, error) {
|
||||
}
|
||||
|
||||
func GetBlockByBlockName(blockName string) (Block, error) {
|
||||
ret := Hash(hashName)
|
||||
if _, err := ret.New(); err != nil {
|
||||
ret := Block(blockName)
|
||||
switch ret {
|
||||
case AES256:
|
||||
return ret, nil
|
||||
default:
|
||||
return "", errors.New("block encryption " + blockName + " is not supported")
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
@@ -43,3 +43,13 @@ func (this BlockMode) GetCipherStream(block cipher.Block, rd io.Reader) (stream
|
||||
}
|
||||
return streamCreator(block, iv), iv, nil
|
||||
}
|
||||
|
||||
func GetBlockModeByName(blockModeName string) (BlockMode, error) {
|
||||
ret := BlockMode(blockModeName)
|
||||
switch ret {
|
||||
case OFB:
|
||||
return ret, nil
|
||||
default:
|
||||
return "", errors.New("block mode " + blockModeName + " is not supported")
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ func (this Hash) New() (hash.Hash, error) {
|
||||
case SHA512:
|
||||
return cryptoSHA512.New(), nil
|
||||
default:
|
||||
msg := fmt.Sprintf("hash '%s' is not supported")
|
||||
msg := fmt.Sprintf("hash '%s' is not supported", this)
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/didiercrunch/filou/contract"
|
||||
"github.com/didiercrunch/filou/helper"
|
||||
)
|
||||
|
||||
type BlockModeStream func(block cipher.Block, iv []byte) cipher.Stream
|
||||
@@ -41,8 +42,14 @@ func GetPayload(dataSource io.Reader, acceptedContract *contract.AcceptedContrac
|
||||
if ret.HashMethod, err = GetHashByHashName(acceptedContract.Hash); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
if ret.Block, err = GetBlockByBlockName(acceptedContract.BlockCipher); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
if ret.BlockMode, err = GetBlockModeByName(acceptedContract.BlockCipherMode); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return ret, helper.JoinErrors(errs)
|
||||
}
|
||||
|
||||
type payloadWriter struct {
|
||||
|
||||
+11
-1
@@ -170,7 +170,11 @@ func TestGetDefaultPayload(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPayload(t *testing.T) {
|
||||
c := &contract.AcceptedContract{Hash: "sha512"}
|
||||
c := &contract.AcceptedContract{
|
||||
Hash: "sha512",
|
||||
BlockCipher: "aes256",
|
||||
BlockCipherMode: "ofb",
|
||||
}
|
||||
p, err := GetPayload(nil, c)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -186,5 +190,11 @@ func TestGetPayload(t *testing.T) {
|
||||
if p.HashMethod != expectedPayload.HashMethod {
|
||||
t.Error("bad hash method")
|
||||
}
|
||||
if p.Block != expectedPayload.Block {
|
||||
t.Error("bad block method", p.Block)
|
||||
}
|
||||
if p.BlockMode != expectedPayload.BlockMode {
|
||||
t.Error("bad block method", p.Block)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user