Skip to content

Commit 0df99a6

Browse files
committed
Intermediate interface for Cryptomator stuff.
1 parent fc05637 commit 0df99a6

20 files changed

+121
-65
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
public class CryptoTransferStatus extends ProxyTransferStatus implements StreamCancelation, StreamProgress {
2828
private static final Logger log = LogManager.getLogger(CryptoTransferStatus.class);
2929

30-
private final CryptoVault vault;
30+
private final CryptoVaultInterface vault;
3131

32-
public CryptoTransferStatus(final CryptoVault vault, final TransferStatus proxy) {
32+
public CryptoTransferStatus(final CryptoVaultInterface vault, final TransferStatus proxy) {
3333
super(proxy);
3434
this.vault = vault;
3535
this.withLength(vault.toCiphertextSize(proxy.getOffset(), proxy.getLength()))

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
// - upon create, the vault version is determined from preferences -> set the delegate impl
8282
// - upon unlock, the vault version needs to be determined by reading masterkey.cryptomator or (!) vault.uvf file -> set the delegate impl
8383
// - open is called either from create or unlock, hence at this point we can delegate calls to the v6/v7/uvf imple?
84-
public class CryptoVault implements Vault {
84+
public class CryptoVault implements CryptoVaultInterface {
8585
private static final Logger log = LogManager.getLogger(CryptoVault.class);
8686

8787
public static final int VAULT_VERSION_DEPRECATED = 6;
@@ -402,16 +402,6 @@ public boolean contains(final Path file) {
402402
return false;
403403
}
404404

405-
@Override
406-
public Path encrypt(final Session<?> session, final Path file) throws BackgroundException {
407-
return this.encrypt(session, file, file.attributes().getDirectoryId(), false);
408-
}
409-
410-
@Override
411-
public Path encrypt(final Session<?> session, final Path file, boolean metadata) throws BackgroundException {
412-
return this.encrypt(session, file, file.attributes().getDirectoryId(), metadata);
413-
}
414-
415405
// UVF: extract to delegate?
416406
public Path encrypt(final Session<?> session, final Path file, final String directoryId, boolean metadata) throws BackgroundException {
417407
final Path encrypted;
@@ -594,38 +584,47 @@ public Path getHome() {
594584
return home;
595585
}
596586

587+
@Override
597588
public Path getMasterkey() {
598589
return masterkey;
599590
}
600591

592+
@Override
601593
public Path getConfig() {
602594
return config;
603595
}
604596

597+
@Override
605598
public FileHeaderCryptor getFileHeaderCryptor() {
606599
return cryptor.fileHeaderCryptor();
607600
}
608601

602+
@Override
609603
public FileContentCryptor getFileContentCryptor() {
610604
return cryptor.fileContentCryptor();
611605
}
612606

607+
@Override
613608
public CryptorCache getFileNameCryptor() {
614609
return fileNameCryptor;
615610
}
616611

612+
@Override
617613
public CryptoFilename getFilenameProvider() {
618614
return filenameProvider;
619615
}
620616

617+
@Override
621618
public CryptoDirectory getDirectoryProvider() {
622619
return directoryProvider;
623620
}
624621

622+
@Override
625623
public int getNonceSize() {
626624
return nonceSize;
627625
}
628626

627+
@Override
629628
public int numberOfChunks(final long cleartextFileSize) {
630629
return (int) (cleartextFileSize / cryptor.fileContentCryptor().cleartextChunkSize() +
631630
((cleartextFileSize % cryptor.fileContentCryptor().cleartextChunkSize() > 0) ? 1 : 0));
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package ch.cyberduck.core.cryptomator;
2+
3+
/*
4+
* Copyright (c) 2002-2025 iterate GmbH. All rights reserved.
5+
* https://cyberduck.io/
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*/
17+
18+
import ch.cyberduck.core.Path;
19+
import ch.cyberduck.core.Session;
20+
import ch.cyberduck.core.exception.BackgroundException;
21+
import ch.cyberduck.core.features.Vault;
22+
23+
import org.cryptomator.cryptolib.api.FileContentCryptor;
24+
import org.cryptomator.cryptolib.api.FileHeaderCryptor;
25+
26+
public interface CryptoVaultInterface extends Vault {
27+
28+
Path getMasterkey();
29+
30+
Path getConfig();
31+
32+
FileHeaderCryptor getFileHeaderCryptor();
33+
34+
FileContentCryptor getFileContentCryptor();
35+
36+
CryptorCache getFileNameCryptor();
37+
38+
CryptoFilename getFilenameProvider();
39+
40+
CryptoDirectory getDirectoryProvider();
41+
42+
int getNonceSize();
43+
44+
int numberOfChunks(long cleartextFileSize);
45+
46+
long toCleartextSize(final long cleartextFileOffset, final long ciphertextFileSize) throws CryptoInvalidFilesizeException;
47+
48+
@Override
49+
default Path encrypt(Session<?> session, Path file) throws BackgroundException {
50+
return this.encrypt(session, file, file.attributes().getDirectoryId(), false);
51+
}
52+
53+
@Override
54+
default Path encrypt(Session<?> session, Path file, boolean metadata) throws BackgroundException {
55+
return this.encrypt(session, file, file.attributes().getDirectoryId(), metadata);
56+
}
57+
58+
Path encrypt(Session<?> session, Path file, String directoryId, boolean metadata) throws BackgroundException;
59+
}

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoBulkFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import ch.cyberduck.core.RandomStringService;
2222
import ch.cyberduck.core.Session;
2323
import ch.cyberduck.core.UUIDRandomStringService;
24-
import ch.cyberduck.core.cryptomator.CryptoVault;
24+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2525
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
2626
import ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator;
2727
import ch.cyberduck.core.exception.BackgroundException;
@@ -46,9 +46,9 @@ public class CryptoBulkFeature<R> implements Bulk<R> {
4646

4747
private final Session<?> session;
4848
private final Bulk<R> delegate;
49-
private final CryptoVault cryptomator;
49+
private final CryptoVaultInterface cryptomator;
5050

51-
public CryptoBulkFeature(final Session<?> session, final Bulk<R> delegate, final Delete delete, final CryptoVault cryptomator) {
51+
public CryptoBulkFeature(final Session<?> session, final Bulk<R> delegate, final Delete delete, final CryptoVaultInterface cryptomator) {
5252
this.session = session;
5353
this.delegate = delegate.withDelete(cryptomator.getFeature(session, Delete.class, delete));
5454
this.cryptomator = cryptomator;

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoChecksumCompute.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import ch.cyberduck.core.cryptomator.CryptoOutputStream;
19-
import ch.cyberduck.core.cryptomator.CryptoVault;
19+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2020
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
2121
import ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator;
2222
import ch.cyberduck.core.exception.BackgroundException;
@@ -55,11 +55,11 @@
5555
public class CryptoChecksumCompute extends AbstractChecksumCompute {
5656
private static final Logger log = LogManager.getLogger(CryptoChecksumCompute.class);
5757

58-
private final CryptoVault cryptomator;
58+
private final CryptoVaultInterface cryptomator;
5959
private final ChecksumCompute delegate;
6060

61-
public CryptoChecksumCompute(final ChecksumCompute delegate, final CryptoVault vault) {
62-
this.cryptomator = vault;
61+
public CryptoChecksumCompute(final ChecksumCompute delegate, final CryptoVaultInterface CryptoVaultInterface) {
62+
this.cryptomator = CryptoVaultInterface;
6363
this.delegate = delegate;
6464
}
6565

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoCopyFeature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import ch.cyberduck.core.Path;
2020
import ch.cyberduck.core.PathAttributes;
2121
import ch.cyberduck.core.Session;
22-
import ch.cyberduck.core.cryptomator.CryptoVault;
22+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2323
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
2424
import ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator;
2525
import ch.cyberduck.core.exception.BackgroundException;
@@ -36,11 +36,11 @@ public class CryptoCopyFeature implements Copy {
3636

3737
private final Session<?> session;
3838
private final Copy proxy;
39-
private final CryptoVault vault;
39+
private final CryptoVaultInterface vault;
4040

4141
private Session<?> target;
4242

43-
public CryptoCopyFeature(final Session<?> session, final Copy proxy, final CryptoVault vault) {
43+
public CryptoCopyFeature(final Session<?> session, final Copy proxy, final CryptoVaultInterface vault) {
4444
this.session = session;
4545
this.target = session;
4646
this.proxy = proxy;

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDeleteV6Feature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import ch.cyberduck.core.Path;
2222
import ch.cyberduck.core.Session;
2323
import ch.cyberduck.core.cryptomator.CryptoFilename;
24-
import ch.cyberduck.core.cryptomator.CryptoVault;
24+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2525
import ch.cyberduck.core.exception.AccessDeniedException;
2626
import ch.cyberduck.core.exception.BackgroundException;
2727
import ch.cyberduck.core.exception.NotfoundException;
@@ -44,10 +44,10 @@ public class CryptoDeleteV6Feature implements Delete, Trash {
4444

4545
private final Session<?> session;
4646
private final Delete proxy;
47-
private final CryptoVault vault;
47+
private final CryptoVaultInterface vault;
4848
private final CryptoFilename filenameProvider;
4949

50-
public CryptoDeleteV6Feature(final Session<?> session, final Delete proxy, final CryptoVault vault) {
50+
public CryptoDeleteV6Feature(final Session<?> session, final Delete proxy, final CryptoVaultInterface vault) {
5151
this.session = session;
5252
this.proxy = proxy;
5353
this.vault = vault;

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDeleteV7Feature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import ch.cyberduck.core.Path;
2323
import ch.cyberduck.core.Session;
2424
import ch.cyberduck.core.cryptomator.CryptoFilename;
25-
import ch.cyberduck.core.cryptomator.CryptoVault;
25+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2626
import ch.cyberduck.core.cryptomator.impl.CryptoDirectoryV7Provider;
2727
import ch.cyberduck.core.exception.AccessDeniedException;
2828
import ch.cyberduck.core.exception.BackgroundException;
@@ -46,10 +46,10 @@ public class CryptoDeleteV7Feature implements Delete, Trash {
4646

4747
private final Session<?> session;
4848
private final Delete proxy;
49-
private final CryptoVault vault;
49+
private final CryptoVaultInterface vault;
5050
private final CryptoFilename filenameProvider;
5151

52-
public CryptoDeleteV7Feature(final Session<?> session, final Delete proxy, final CryptoVault vault) {
52+
public CryptoDeleteV7Feature(final Session<?> session, final Delete proxy, final CryptoVaultInterface vault) {
5353
this.session = session;
5454
this.proxy = proxy;
5555
this.vault = vault;

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryV6Feature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import ch.cyberduck.core.Session;
2121
import ch.cyberduck.core.UUIDRandomStringService;
2222
import ch.cyberduck.core.cryptomator.ContentWriter;
23-
import ch.cyberduck.core.cryptomator.CryptoVault;
23+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2424
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
2525
import ch.cyberduck.core.exception.BackgroundException;
2626
import ch.cyberduck.core.features.Directory;
@@ -40,11 +40,11 @@ public class CryptoDirectoryV6Feature<Reply> implements Directory<Reply> {
4040
private final Session<?> session;
4141
private final Write<Reply> writer;
4242
private final Directory<Reply> delegate;
43-
private final CryptoVault vault;
43+
private final CryptoVaultInterface vault;
4444
private final RandomStringService random = new UUIDRandomStringService();
4545

4646
public CryptoDirectoryV6Feature(final Session<?> session, final Directory<Reply> delegate,
47-
final Write<Reply> writer, final CryptoVault cryptomator) {
47+
final Write<Reply> writer, final CryptoVaultInterface cryptomator) {
4848
this.session = session;
4949
this.writer = writer;
5050
this.delegate = delegate;

cryptomator/src/main/java/ch/cyberduck/core/cryptomator/features/CryptoDirectoryV7Feature.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import ch.cyberduck.core.Session;
2121
import ch.cyberduck.core.UUIDRandomStringService;
2222
import ch.cyberduck.core.cryptomator.ContentWriter;
23-
import ch.cyberduck.core.cryptomator.CryptoVault;
23+
import ch.cyberduck.core.cryptomator.CryptoVaultInterface;
2424
import ch.cyberduck.core.cryptomator.impl.CryptoDirectoryV7Provider;
2525
import ch.cyberduck.core.cryptomator.random.RandomNonceGenerator;
2626
import ch.cyberduck.core.exception.BackgroundException;
@@ -42,11 +42,11 @@ public class CryptoDirectoryV7Feature<Reply> implements Directory<Reply> {
4242
private final Session<?> session;
4343
private final Write<Reply> writer;
4444
private final Directory<Reply> delegate;
45-
private final CryptoVault vault;
45+
private final CryptoVaultInterface vault;
4646
private final RandomStringService random = new UUIDRandomStringService();
4747

4848
public CryptoDirectoryV7Feature(final Session<?> session, final Directory<Reply> delegate,
49-
final Write<Reply> writer, final CryptoVault cryptomator) {
49+
final Write<Reply> writer, final CryptoVaultInterface cryptomator) {
5050
this.session = session;
5151
this.writer = writer;
5252
this.delegate = delegate;

0 commit comments

Comments
 (0)