$this->unencryptedSize = 0;
} else {
$this->size = $this->rootView->filesize($this->rawPath);
++<<<<<<< HEAD
+ \OC_FileProxy::$enabled = true;
+ $this->unencryptedSize = $this->rootView->filesize($this->rawPath);
+ \OC_FileProxy::$enabled = false;
+ $this->readHeader();
++=======
+ $this->readHeader();
+ }
+
+ if ($this->isLocalTmpFile) {
+ $this->handle = fopen($this->localTmpFile, $mode);
+ } else {
+ $this->handle = $this->rootView->fopen($this->rawPath, $mode);
++>>>>>>> origin/master
}
\OC_FileProxy::$enabled = $proxyStatus;
*/
public function stream_read($count) {
++<<<<<<< HEAD
+ $result = '';
++=======
+ $this->writeCache = '';
+
+ if ($count !== Crypt::BLOCKSIZE) {
+ \OCP\Util::writeLog('Encryption library', 'PHP "bug" 21641 no longer holds, decryption system requires refactoring', \OCP\Util::FATAL);
+ throw new EncryptionException('expected a block size of 8192 byte', EncryptionException::UNEXPECTED_BLOCK_SIZE);
+ }
+
+ // Get the data from the file handle
+ $data = fread($this->handle, $count);
++>>>>>>> origin/master
- // if this block contained the header we move on to the next block
- if (Crypt::isHeader($data)) {
- $data = fread($this->handle, $count);
- }
-
- $result = null;
+ // limit to the end of the unencrypted file; otherwise getFileSize will fail and it is good practise anyway
+ $count=min($count,$this->unencryptedSize - $this->position);
- if (strlen($data)) {
+ // loop over the 6126 sized unencrypted blocks
+ while ($count > 0) {
- if (!$this->getKey()) {
+ $remainingLength = $count;
- // Error! We don't have a key to decrypt the file with
- throw new \Exception(
- 'Encryption key not found for "' . $this->rawPath . '" during attempted read via stream');
+ // update the cache of the current block
+ $this->readCache();
+
+ // determine the relative position in the current block
+ $blockPosition=($this->position % 6126);
+ // if entire read inside current block then only position needs to be updated
+ if ($remainingLength<(6126 - $blockPosition)) {
+ $result .= substr($this->cache,$blockPosition,$remainingLength);
+ $this->position += $remainingLength;
+ $count=0;
+ // otherwise remainder of current block is fetched, the block is flushed and the position updated
} else {
-
- // Decrypt data
- $result = Crypt::symmetricDecryptFileContent($data, $this->plainKey, $this->cipher);
+ $result .= substr($this->cache,$blockPosition);
+ $this->flush();
+ $this->position += (6126 - $blockPosition);
+ $count -= (6126 - $blockPosition);
}
}
}
+ <<<<<<< HEAD
+ $util = new Util($this->rootView, $this->userId);
+
+ // Fetch and decrypt keyfile
+ // Fetch existing keyfile
++<<<<<<< HEAD
++ $this->encKeyfile = Keymanager::getFileKey($this->rootView, $this->util, $this->relPath);
++=======
+ $this->encKeyfile = Keymanager::getFileKey($this->rootView, $util, $this->relPath);
+ =======
+ // $util = new Util($this->rootView, $this->userId);
+
// Fetch and decrypt keyfile
// Fetch existing keyfile
$this->encKeyfile = Keymanager::getFileKey($this->rootView, $this->util, $this->relPath);
++>>>>>>> origin/master
+ >>>>>>> origin/master
// If a keyfile already exists
if ($this->encKeyfile) {