MCPcopy
hub / github.com/rclone/rclone / newEncrypter

Method newEncrypter

backend/crypt/cipher.go:694–716  ·  view source on GitHub ↗

newEncrypter creates a new file handle encrypting on the fly

(in io.Reader, nonce *nonce)

Source from the content-addressed store, hash-verified

692
693// newEncrypter creates a new file handle encrypting on the fly
694func (c *Cipher) newEncrypter(in io.Reader, nonce *nonce) (*encrypter, error) {
695 fh := &encrypter{
696 in: in,
697 c: c,
698 buf: c.getBlock(),
699 readBuf: c.getBlock(),
700 bufSize: fileHeaderSize,
701 }
702 // Initialise nonce
703 if nonce != nil {
704 fh.nonce = *nonce
705 } else {
706 err := fh.nonce.fromReader(c.cryptoRand)
707 if err != nil {
708 return nil, err
709 }
710 }
711 // Copy magic into buffer
712 copy((*fh.buf)[:], fileMagicBytes)
713 // Copy nonce into buffer
714 copy((*fh.buf)[fileMagicSize:], fh.nonce[:])
715 return fh, nil
716}
717
718// Read as per io.Reader
719func (fh *encrypter) Read(p []byte) (n int, err error) {

Callers 6

encryptDataMethod · 0.95
computeHashWithNonceMethod · 0.80
testObjectInfoFunction · 0.80
testEncryptDecryptFunction · 0.80
TestNewEncrypterFunction · 0.80

Calls 3

getBlockMethod · 0.95
copyStruct · 0.85
fromReaderMethod · 0.80

Tested by 4

testObjectInfoFunction · 0.64
testEncryptDecryptFunction · 0.64
TestNewEncrypterFunction · 0.64