MCPcopy
hub / github.com/rclone/rclone / newDecrypter

Method newDecrypter

backend/crypt/cipher.go:793–818  ·  view source on GitHub ↗

newDecrypter creates a new file handle decrypting on the fly

(rc io.ReadCloser)

Source from the content-addressed store, hash-verified

791
792// newDecrypter creates a new file handle decrypting on the fly
793func (c *Cipher) newDecrypter(rc io.ReadCloser) (*decrypter, error) {
794 fh := &decrypter{
795 rc: rc,
796 c: c,
797 buf: c.getBlock(),
798 readBuf: c.getBlock(),
799 limit: -1,
800 }
801 // Read file header (magic + nonce)
802 readBuf := (*fh.readBuf)[:fileHeaderSize]
803 n, err := readers.ReadFill(fh.rc, readBuf)
804 if n < fileHeaderSize && err == io.EOF {
805 // This read from 0..fileHeaderSize-1 bytes
806 return nil, fh.finishAndClose(ErrorEncryptedFileTooShort)
807 } else if err != io.EOF && err != nil {
808 return nil, fh.finishAndClose(err)
809 }
810 // check the magic
811 if !bytes.Equal(readBuf[:fileMagicSize], fileMagicBytes) {
812 return nil, fh.finishAndClose(ErrorEncryptedBadMagic)
813 }
814 // retrieve the nonce
815 fh.nonce.fromBuf(readBuf[fileMagicSize:])
816 fh.initialNonce = fh.nonce
817 return fh, nil
818}
819
820// newDecrypterSeek creates a new file handle decrypting on the fly
821func (c *Cipher) newDecrypterSeek(ctx context.Context, open OpenRangeSeek, offset, limit int64) (fh *decrypter, err error) {

Callers 8

newDecrypterSeekMethod · 0.95
DecryptDataMethod · 0.95
ComputeHashMethod · 0.80
testEncryptDecryptFunction · 0.80
TestNewDecrypterFunction · 0.80
TestDecrypterReadFunction · 0.80
TestDecrypterCloseFunction · 0.80

Calls 5

getBlockMethod · 0.95
finishAndCloseMethod · 0.95
ReadFillFunction · 0.92
fromBufMethod · 0.80
EqualMethod · 0.45

Tested by 5

testEncryptDecryptFunction · 0.64
TestNewDecrypterFunction · 0.64
TestDecrypterReadFunction · 0.64
TestDecrypterCloseFunction · 0.64