move master to main #1

Merged
erius merged 18 commits from master into main 2024-06-05 17:39:20 +00:00
Showing only changes of commit c0293f8599 - Show all commits

View file

@ -6,10 +6,53 @@ import (
"io"
)
type cipherReader struct {
r io.Reader
prng io.Reader
}
type cipherWriter struct {
w io.Writer
prng io.Reader
}
func (c *cipherReader) Read(p []byte) (n int, err error) {
n, err = c.r.Read(p)
if err != nil {
if err == io.EOF {
p = p[:n]
} else {
return
}
}
rand := make([]byte, n)
_, rngErr := c.prng.Read(rand)
if rngErr != nil {
return
}
for i := 0; i < n; i++ {
p[i] ^= rand[i]
}
return
}
func (c *cipherWriter) Write(p []byte) (n int, err error) {
data := make([]byte, len(p))
_, err = c.prng.Read(data)
if err != nil {
return
}
for i := 0; i < len(p); i++ {
data[i] ^= p[i]
}
n, err = c.w.Write(data)
return
}
func NewReader(r io.Reader, prng io.Reader) io.Reader {
panic("implement me")
return &cipherReader{r, prng}
}
func NewWriter(w io.Writer, prng io.Reader) io.Writer {
panic("implement me")
return &cipherWriter{w, prng}
}