* blocks with encryption alone, hence padding is added to achieve the \r
* required length. \r
*/\r
- public static function addPadding( $data ) {
-
- $padded = $data . 'xx';
-
- return $padded;
-
- }
-
- /**
- * @brief Remove arbitrary padding to encrypted data
- * @param string $padded padded data to remove padding from
- * @return unpadded data on success, false on error
- */
- public static function removePadding( $padded ) {
-
- if ( substr( $padded, -2 ) == 'xx' ) {
-
- $data = substr( $padded, 0, -2 );
-
- return $data;
-
- } else {
-
- // TODO: log the fact that unpadded data was submitted for removal of padding
- return false;
-
- }
-
- }
-
- /**
- * @brief Check if a file's contents contains an IV and is symmetrically encrypted
- * @return true / false
- * @note see also OCA\Encryption\Util->isEncryptedPath()
- */
- public static function isCatfile( $content ) {
-
- if ( !$content ) {
-
- return false;
-
- }
-
- $noPadding = self::removePadding( $content );
-
- // Fetch encryption metadata from end of file
- $meta = substr( $noPadding, -22 );
-
- // Fetch IV from end of file
- $iv = substr( $meta, -16 );
-
- // Fetch identifier from start of metadata
- $identifier = substr( $meta, 0, 6 );
-
- if ( $identifier == '00iv00') {
-
- return true;
-
- } else {
-
- return false;
-
- }
-
- }
-
- /**
- * Check if a file is encrypted according to database file cache
- * @param string $path
- * @return bool
- */
- public static function isEncryptedMeta( $path ) {
-
- // TODO: Use DI to get \OC\Files\Filesystem out of here
-
- // Fetch all file metadata from DB
- $metadata = \OC\Files\Filesystem::getFileInfo( $path, '' );
-
- // Return encryption status
- return isset( $metadata['encrypted'] ) and ( bool )$metadata['encrypted'];
-
- }
+ public static function addPadding( $data ) {\r
+ \r
+ $padded = $data . 'xx';\r
+ \r
+ return $padded;\r
+ \r
+ }\r
+ \r
+ /**\r
+ * @brief Remove arbitrary padding to encrypted data\r
+ * @param string $padded padded data to remove padding from\r
+ * @return unpadded data on success, false on error\r
+ */\r
+ public static function removePadding( $padded ) {\r
+ \r
+ if ( substr( $padded, -2 ) == 'xx' ) {\r
+ \r
+ $data = substr( $padded, 0, -2 );\r
+ \r
+ return $data;\r
+ \r
+ } else {\r
+ \r
+ // TODO: log the fact that unpadded data was submitted for removal of padding\r
+ return false;\r
+ \r
+ }\r
+ \r
+ }\r
+ \r
+ /**\r
+ * @brief Check if a file's contents contains an IV and is symmetrically encrypted\r
+ * @return true / false\r
+ * @note see also OCA\Encryption\Util->isEncryptedPath()\r
+ */\r
+ public static function isCatfile( $content ) {\r
++ \r
++ if ( !$content ) {\r
++ \r
++ return false;\r
++ \r
++ }\r
+ \r
+ $noPadding = self::removePadding( $content );\r
+ \r
+ // Fetch encryption metadata from end of file\r
+ $meta = substr( $noPadding, -22 );\r
+ \r
+ // Fetch IV from end of file\r
+ $iv = substr( $meta, -16 );\r
+ \r
+ // Fetch identifier from start of metadata\r
+ $identifier = substr( $meta, 0, 6 );\r
+ \r
+ if ( $identifier == '00iv00') {\r
+ \r
+ return true;\r
+ \r
+ } else {\r
+ \r
+ return false;\r
+ \r
+ }\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Check if a file is encrypted according to database file cache\r
+ * @param string $path\r
+ * @return bool\r
+ */\r
+ public static function isEncryptedMeta( $path ) {\r
+ \r
+ // TODO: Use DI to get \OC\Files\Filesystem out of here\r
+ \r
+ // Fetch all file metadata from DB\r
+ $metadata = \OC\Files\Filesystem::getFileInfo( $path, '' );\r
+ \r
+ // Return encryption status\r
+ return isset( $metadata['encrypted'] ) and ( bool )$metadata['encrypted'];\r
+ \r
+ }\r
\r
/**\r
* @brief Check if a file is encrypted via legacy system\r