aboutsummaryrefslogtreecommitdiff
path: root/iowrp.go
diff options
context:
space:
mode:
authorSina Ghaderi <khokooli@gmail.com>2022-01-23 07:17:19 +0330
committerSina Ghaderi <khokooli@gmail.com>2022-01-23 07:17:19 +0330
commit42b54e4394977c34c8cf738a1d19f9b37a6a8c5e (patch)
treeab60feff9575cf9b6d9507b59aa45c72baf0c77c /iowrp.go
add source code
Diffstat (limited to 'iowrp.go')
-rw-r--r--iowrp.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/iowrp.go b/iowrp.go
new file mode 100644
index 0000000..212d658
--- /dev/null
+++ b/iowrp.go
@@ -0,0 +1,26 @@
+package rabbitio
+
+import (
+ "crypto/cipher"
+ "io"
+)
+
+// NewWriterCipher warp a rabbit cipher stream with an io.Writer, returned StreamWriter
+// interface witch can be used to encrypt or decrypting data
+func NewWriterCipher(key []byte, iv []byte, wr io.Writer) (*cipher.StreamWriter, error) {
+ stream, err := NewCipher(key, iv)
+ if err != nil {
+ return nil, err
+ }
+ return &cipher.StreamWriter{S: stream, W: wr}, err
+}
+
+// NewWriterCipher warp a rabbit cipher stream with an io.Reader, returned StreamReader
+// interface witch can be used to encrypt or decrypting data
+func NewReaderCipher(key []byte, iv []byte, re io.Reader) (*cipher.StreamReader, error) {
+ stream, err := NewCipher(key, iv)
+ if err != nil {
+ return nil, err
+ }
+ return &cipher.StreamReader{S: stream, R: re}, err
+}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR