Skip to content

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jul 19, 2021
1 parent 6440ec3 commit c9533b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/cryptomator/siv/SivMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SivMode() {
* @see #SivMode(BlockCipherFactory)
*/
public SivMode(final Provider jceSecurityProvider) {
this(ThreadLocal.withInitial(() -> new JceAesBlockCipher(jceSecurityProvider)), new JceAesCtrComputer(jceSecurityProvider));
this(ThreadLocals.withInitial(() -> new JceAesBlockCipher(jceSecurityProvider)), new JceAesCtrComputer(jceSecurityProvider));
}

/**
Expand All @@ -60,7 +60,7 @@ public SivMode(final Provider jceSecurityProvider) {
* @param cipherFactory A factory method creating a Blockcipher.get(). Must use a block size of 128 bits (16 bytes).
*/
public SivMode(final BlockCipherFactory cipherFactory) {
this(ThreadLocal.withInitial(() -> cipherFactory.create()));
this(ThreadLocals.withInitial(() -> cipherFactory.create()));
}

private SivMode(final ThreadLocal<BlockCipher> threadLocalCipher) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/cryptomator/siv/ThreadLocals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.cryptomator.siv;

import java.util.function.Supplier;

class ThreadLocals {

static <S> ThreadLocal<S> withInitial(Supplier<S> supplier) {
// ThreadLocal.withInitial is unavailable on Android 7.x
return new ThreadLocal<S>() {
@Override
protected S initialValue() {
return supplier.get();
}
};
}

}
11 changes: 11 additions & 0 deletions src/main/java9/org.cryptomator.siv/ThreadLocals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.cryptomator.siv;

import java.util.function.Supplier;

class ThreadLocals {

static <S> ThreadLocal<S> withInitial(Supplier<S> supplier) {
return ThreadLocal.withInitial(supplier);
}

}

0 comments on commit c9533b0

Please sign in to comment.