change computer
This commit is contained in:
1 parent
7a5c9c79a5
commit
76e166730f
2 files changed
+55
-5
No files matched your search
+32
-5
@@ -3,11 +3,13 @@ package payload
|
|||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
var _ = fmt.Print
|
||||||
|
|
||||||
|
/*
|
||||||
type Payload interface {
|
type Payload interface {
|
||||||
GetHash() []byte
|
GetHash() []byte
|
||||||
GetKey() []byte
|
GetKey() []byte
|
||||||
@@ -16,14 +18,19 @@ import (
|
|||||||
GetHashMethod() string
|
GetHashMethod() string
|
||||||
GetPayloadData() io.Reader
|
GetPayloadData() io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
type BlockMode string
|
||||||
|
|
||||||
|
const OFB BlockMode = "ofb"
|
||||||
|
|
||||||
|
type BlockModeStream func(block cipher.Block, iv []byte) cipher.Stream
|
||||||
|
|
||||||
type Payload struct {
|
type Payload struct {
|
||||||
DataSource io.Reader
|
DataSource io.Reader
|
||||||
Hash crypto.Hash
|
Hash crypto.Hash
|
||||||
Block cipher.Block
|
Block Block
|
||||||
BlockMode cipher.Stream
|
BlockMode BlockMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Payload) GetHashMethod() string {
|
func (this *Payload) GetHashMethod() string {
|
||||||
@@ -52,6 +59,26 @@ func (this *Payload) GetHashMethod() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Payload) GetPayloadData() io.Reader {
|
func (this *Payload) GetPayloadData() io.Reader {
|
||||||
// this.BlockMode.
|
// zip data source
|
||||||
|
|
||||||
|
// create metadata
|
||||||
|
// zip the zipped data and metadata
|
||||||
|
|
||||||
|
// encryptp everything togeter
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Payload) getStream() cipher.Stream {
|
||||||
|
return nil //this.BlockMode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Payload) encrypt(reader io.Reader) io.Reader {
|
||||||
|
ret, writer := io.Pipe()
|
||||||
|
go func() {
|
||||||
|
cipherWriter := &cipher.StreamWriter{S: this.getStream(), W: writer}
|
||||||
|
io.Copy(cipherWriter, reader)
|
||||||
|
cipherWriter.Close()
|
||||||
|
}()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package payload
|
package payload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto"
|
"crypto"
|
||||||
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,5 +25,26 @@ func TestPayloadGetHashMethod(t *testing.T) {
|
|||||||
t.Error("bad hash name. supposed to be ", name, " but received", returnedName)
|
t.Error("bad hash name. supposed to be ", name, " but received", returnedName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetStream(t *testing.T) {
|
||||||
|
p := new(Payload)
|
||||||
|
if s := p.getStream(); s != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncrypt(t *testing.T) {
|
||||||
|
if true {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p := new(Payload)
|
||||||
|
data := bytes.NewBufferString("nice string")
|
||||||
|
reader := p.encrypt(data)
|
||||||
|
if outputdata, err := ioutil.ReadAll(reader); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if string(outputdata) != "nice string" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user