Skip to content

Commit ff70585

Browse files
ylangiscdkocher
authored andcommitted
Fix UVF impl.
1 parent 662ef51 commit ff70585

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/UVFVault.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ public Path encrypt(Session<?> session, Path file, boolean metadata) throws Back
198198
else {
199199
parent = this.getDirectoryProvider().toEncrypted(session, file.getParent());
200200
// / diff to AbstractVault.encrypt
201-
String filenameO = this.getDirectoryProvider().toEncrypted(session, parent, file.getName(), file.getType());
202-
filename = ((CryptoDirectoryUVFProvider) this.getDirectoryProvider()).toEncrypted(session, file.getParent(), file.getName());
201+
filename = this.getDirectoryProvider().toEncrypted(session, file.getParent(), file.getName(), file.getType());
203202
// \ diff to AbstractVault.decrypt
204203
}
205204
final PathAttributes attributes = new PathAttributes(file.attributes());

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/impl/CryptoDirectoryUVFProvider.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.cryptomator.cryptolib.api.FileHeader;
3434

3535
import java.nio.ByteBuffer;
36+
import java.nio.ByteOrder;
3637
import java.nio.charset.StandardCharsets;
3738
import java.util.EnumSet;
3839

@@ -60,15 +61,15 @@ public CryptoDirectoryUVFProvider(final AbstractVault vault, final CryptoFilenam
6061
}
6162

6263
@Override
63-
protected byte[] toDirectoryId(final Session<?> session, final Path directory, final byte[] directoryId) throws BackgroundException {
64+
protected byte[] toDirectoryId(final Session<?> session, final Path directory) throws BackgroundException {
6465
if(new SimplePathPredicate(home).test(directory)) {
6566
return vault.getRootDirId();
6667
}
67-
return super.toDirectoryId(session, directory, directoryId);
68+
return super.toDirectoryId(session, directory);
6869
}
6970

70-
// interface mismatch: we need parent path to get dirId and revision from dir.uvf
71-
public String toEncrypted(final Session<?> session, final Path parent, final String filename) throws BackgroundException {
71+
@Override
72+
public String toEncrypted(final Session<?> session, final Path parent, final String filename, final EnumSet<Path.Type> type) throws BackgroundException {
7273
if(new SimplePathPredicate(home).test(parent)) {
7374
final String ciphertextName = filenameCryptor.encryptFilename(BaseEncoding.base64Url(), filename, vault.getRootDirId()) + vault.getRegularFileExtension();
7475
log.debug("Encrypted filename {} to {}", filename, ciphertextName);
@@ -121,7 +122,7 @@ protected byte[] load(final Session<?> session, final Path directory) throws Bac
121122
}
122123
final Path parent = this.toEncrypted(session, directory.getParent());
123124
final String cleartextName = directory.getName();
124-
final String ciphertextName = this.toEncrypted(session, parent, cleartextName, EnumSet.of(Path.Type.directory));
125+
final String ciphertextName = this.toEncrypted(session, directory.getParent(), cleartextName, EnumSet.of(Path.Type.directory));
125126
final Path metadataParent = new Path(parent, ciphertextName, EnumSet.of(Path.Type.directory));
126127
// Read directory id from file
127128
try {
@@ -154,12 +155,9 @@ protected byte[] load(final Session<?> session, final Path directory) throws Bac
154155
}
155156

156157
protected int loadRevision(final Session<?> session, final Path directory) throws BackgroundException {
157-
//TODO
158-
159-
/*
160-
final Path parent = this.toEncrypted(session, directory.getParent().attributes().getDirectoryId(), directory.getParent());
158+
final Path parent = this.toEncrypted(session, directory.getParent());
161159
final String cleartextName = directory.getName();
162-
final String ciphertextName = this.toEncrypted(session, parent.attributes().getDirectoryId(), cleartextName, EnumSet.of(Path.Type.directory));
160+
final String ciphertextName = this.toEncrypted(session, directory.getParent(), cleartextName, EnumSet.of(Path.Type.directory));
163161
final Path metadataParent = new Path(parent, ciphertextName, EnumSet.of(Path.Type.directory));
164162
// Read directory id from file
165163
log.debug("Read directory ID for folder {} from {}", directory, ciphertextName);
@@ -174,7 +172,6 @@ protected int loadRevision(final Session<?> session, final Path directory) throw
174172
ByteBuffer buffer = ByteBuffer.wrap(ciphertext);
175173
ByteBuffer headerBuf = buffer.duplicate();
176174
headerBuf.position(4).limit(headerSize);
177-
return headerBuf.order(ByteOrder.BIG_ENDIAN).getInt();*/
178-
return 0;
175+
return headerBuf.order(ByteOrder.BIG_ENDIAN).getInt();
179176
}
180177
}

0 commit comments

Comments
 (0)