1
0
mirror of https://github.com/etesync/android synced 2024-11-16 04:49:06 +00:00

JournalManager: rename Helpers to Crypto.

These are crypto helpers, this should have been named this way from the start.
This commit is contained in:
Tom Hacohen 2017-03-29 12:11:08 +01:00
parent 225d01c143
commit 0fbee1ea02
5 changed files with 11 additions and 11 deletions

View File

@ -19,7 +19,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import static com.etesync.syncadapter.journalmanager.Helpers.hmac;
import static com.etesync.syncadapter.journalmanager.Crypto.hmac;
abstract class BaseManager {
final static protected MediaType JSON = MediaType.parse("application/json; charset=utf-8");
@ -77,12 +77,12 @@ abstract class BaseManager {
public String getContent(String keyBase64) {
// FIXME: probably cache encryption object
return new String(new Helpers.Cipher().decrypt(keyBase64, content), Charsets.UTF_8);
return new String(new Crypto.Cipher().decrypt(keyBase64, content), Charsets.UTF_8);
}
void setContent(String keyBase64, String content) {
// FIXME: probably cache encryption object
this.content = new Helpers.Cipher().encrypt(keyBase64, content.getBytes(Charsets.UTF_8));
this.content = new Crypto.Cipher().encrypt(keyBase64, content.getBytes(Charsets.UTF_8));
}
byte[] calculateHmac(String keyBase64, String uuid) {

View File

@ -23,7 +23,7 @@ import java.util.Arrays;
import com.etesync.syncadapter.App;
public class Helpers {
public class Crypto {
// FIXME: This should be somewhere else
public static String deriveKey(String salt, String password) {
final int keySize = 190;
@ -123,7 +123,7 @@ public class Helpers {
return sha256(base.getBytes(Charsets.UTF_8));
}
static String sha256(byte[] base) {
private static String sha256(byte[] base) {
SHA256Digest digest = new SHA256Digest();
digest.update(base, 0, base.length);
byte[] ret = new byte[digest.getDigestSize()];
@ -131,7 +131,7 @@ public class Helpers {
return toHex(ret);
}
public static String toHex(byte[] bytes) {
static String toHex(byte[] bytes) {
return Hex.toHexString(bytes).toLowerCase();
}
}

View File

@ -109,7 +109,7 @@ public class JournalEntryManager extends BaseManager {
uuid = previous.getUuid();
}
return Helpers.toHex(calculateHmac(keyBase64, uuid));
return Crypto.toHex(calculateHmac(keyBase64, uuid));
}
}

View File

@ -17,8 +17,8 @@ import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import static com.etesync.syncadapter.journalmanager.Helpers.sha256;
import static com.etesync.syncadapter.journalmanager.Helpers.toHex;
import static com.etesync.syncadapter.journalmanager.Crypto.sha256;
import static com.etesync.syncadapter.journalmanager.Crypto.toHex;
public class JournalManager extends BaseManager {
final static private Type journalType = new TypeToken<List<Journal>>() {

View File

@ -33,7 +33,7 @@ import com.etesync.syncadapter.App;
import com.etesync.syncadapter.Constants;
import com.etesync.syncadapter.InvalidAccountException;
import com.etesync.syncadapter.R;
import com.etesync.syncadapter.journalmanager.Helpers;
import com.etesync.syncadapter.journalmanager.Crypto;
import com.etesync.syncadapter.model.CollectionInfo;
import com.etesync.syncadapter.model.JournalEntity;
import com.etesync.syncadapter.model.ServiceDB;
@ -112,7 +112,7 @@ public class SetupEncryptionFragment extends DialogFragment implements LoaderMan
@Override
public Configuration loadInBackground() {
config.password = Helpers.deriveKey(config.userName, config.rawPassword);
config.password = Crypto.deriveKey(config.userName, config.rawPassword);
return config;
}
}