continued work on encryption

This commit is contained in:
ston1th 2022-04-07 00:54:13 +02:00
commit 880e2f06b3
14 changed files with 362 additions and 39 deletions

View file

@ -4,6 +4,7 @@ import (
"cachefs/pkg/chunk"
"crypto/cipher"
"errors"
"fmt"
"io"
"golang.org/x/crypto/chacha20poly1305"
@ -71,7 +72,9 @@ func (c *chunkWriter) full() bool {
func (c *chunkWriter) flush(last bool) (n int, err error) {
wb := c.buf[:0]
if last {
fmt.Println("last nonce", c.nonce)
setLastChunkFlag(&c.nonce)
fmt.Println("last nonce flag", c.nonce)
s := c.chunks.Size()
wb = c.buf[:s]
n = int(s)
@ -112,15 +115,19 @@ func (w *writer) Write(p []byte) (n int, err error) {
}
func (w *writer) Close() error {
fmt.Println("writer closed", w.err)
if w.err != nil {
return w.err
}
if w.last != nil {
fmt.Println("flushing last chunk")
_, w.err = w.last.flush(lastChunk)
if w.err != nil {
fmt.Println("error flushing last chunk", w.err)
return w.err
}
w.flush = false
}
if w.flush {