Skip to content

Commit

Permalink
Added cleartext size calculation during metadata conversion in crypto…
Browse files Browse the repository at this point in the history
… decorator
  • Loading branch information
tobihagemann committed Jun 22, 2020
1 parent 4049445 commit 139962c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CloudAccess/VaultFormat7/VaultFormat7ProviderDecorator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,16 @@ public class VaultFormat7ProviderDecorator: CloudProvider {
let ciphertextBaseName = String(ciphertextMetadata.name.prefix(ciphertextMetadata.name.count - 4))
let cleartextName = try self.cryptor.decryptFileName(ciphertextBaseName, dirId: parentDirId)
let cleartextURL = cleartextParentURL.appendingPathComponent(cleartextName, isDirectory: ciphertextMetadata.itemType == .folder)
let cleartextSize = 0 // TODO: determine cleartext size
let cleartextSize = try { () -> Int? in
guard let ciphertextSize = ciphertextMetadata.size else {
return nil
}
if ciphertextMetadata.itemType == .file {
return try self.cryptor.calculateCleartextSize(ciphertextSize)
} else {
return ciphertextSize
}
}()
return CloudItemMetadata(name: cleartextName, remoteURL: cleartextURL, itemType: ciphertextMetadata.itemType, lastModifiedDate: ciphertextMetadata.lastModifiedDate, size: cleartextSize)
}
}
Expand Down
8 changes: 8 additions & 0 deletions CloudAccessTests/VaultFormat7/CryptorMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ public class CryptorMock: Cryptor {
throw CryptorMockError.notMocked
}
}

override public func calculateCiphertextSize(_ cleartextSize: Int) -> Int {
return 0
}

override public func calculateCleartextSize(_ ciphertextSize: Int) throws -> Int {
return 0
}
}

0 comments on commit 139962c

Please sign in to comment.