diff --git a/build.gradle b/build.gradle
index f1cdcdf..c65b2ff 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,6 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
+ classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -13,15 +14,7 @@ buildscript {
}
}
-
-def isReleaseBuild() {
- return version.contains("SNAPSHOT") == false
-}
-
allprojects {
- version = VERSION_NAME
- group = GROUP
-
repositories {
jcenter()
}
diff --git a/checkstyle.xml b/checkstyle.xml
new file mode 100755
index 0000000..2b95aba
--- /dev/null
+++ b/checkstyle.xml
@@ -0,0 +1,149 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/gradle.properties b/gradle.properties
deleted file mode 100644
index 135f5b8..0000000
--- a/gradle.properties
+++ /dev/null
@@ -1,34 +0,0 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-# Default value: -Xmx10248m -XX:MaxPermSize=256m
-# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
-
-# VERSION_NAME=1.10-SNAPSHOT
-VERSION_NAME=1.18
-VERSION_CODE=19
-GROUP=com.orhanobut
-
-POM_DESCRIPTION=Secure, Advanced Storage for android
-POM_URL=https://github.com/orhanobut/hawk
-POM_SCM_URL=https://github.com/orhanobut/hawk
-POM_SCM_CONNECTION=scm:git@https://github.com/orhanobut/hawk.git
-POM_SCM_DEV_CONNECTION=scm:git@https://github.com/orhanobut/hawk.git
-POM_LICENCE_NAME=The Apache Software License, Version 2.0
-POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
-POM_LICENCE_DIST=repo
-POM_DEVELOPER_ID=nr4bt
-POM_DEVELOPER_NAME=Orhan Obut
\ No newline at end of file
diff --git a/hawk/build.gradle b/hawk/build.gradle
index 55b8f5d..a57def3 100644
--- a/hawk/build.gradle
+++ b/hawk/build.gradle
@@ -1,11 +1,25 @@
apply plugin: 'com.android.library'
+apply plugin: 'com.github.dcendents.android-maven'
+
+apply plugin: 'checkstyle'
+
+check.dependsOn('checkstyle')
+
+task checkstyle(type: Checkstyle) {
+ configFile = rootProject.file('checkstyle.xml')
+ source 'src'
+ include '**/*.java'
+ exclude '**/gen/**'
+
+ classpath = files()
+}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
- minSdkVersion 8
+ minSdkVersion 9
targetSdkVersion 21
}
@@ -14,6 +28,24 @@ android {
}
}
+// build a jar with source files
+task sourcesJar(type: Jar) {
+ from android.sourceSets.main.java.srcDirs
+ classifier = 'sources'
+}
+
+task javadoc(type: Javadoc) {
+ failOnError false
+ source = android.sourceSets.main.java.sourceFiles
+ classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+}
+
+// build a jar with javadoc
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier = 'javadoc'
+ from javadoc.destinationDir
+}
+
configurations {
optional
compile.extendsFrom optional
@@ -21,12 +53,10 @@ configurations {
dependencies {
compile 'com.google.code.gson:gson:2.3.1'
- optional 'io.reactivex:rxandroid:0.25.0'
+ optional 'io.reactivex:rxandroid:1.0.1'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
testCompile "org.robolectric:robolectric:3.0"
testCompile 'org.assertj:assertj-core:1.7.0'
-}
-
-apply from: '../maven_push.gradle'
+}
\ No newline at end of file
diff --git a/hawk/src/main/AndroidManifest.xml b/hawk/src/main/AndroidManifest.xml
index 5cfc3b6..3f984b0 100644
--- a/hawk/src/main/AndroidManifest.xml
+++ b/hawk/src/main/AndroidManifest.xml
@@ -1,9 +1,3 @@
-
-
-
-
-
-
+
+
diff --git a/hawk/src/main/java/com/orhanobut/hawk/AesCbcWithIntegrity.java b/hawk/src/main/java/com/orhanobut/hawk/AesCbcWithIntegrity.java
index 2baa954..701d798 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/AesCbcWithIntegrity.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/AesCbcWithIntegrity.java
@@ -73,10 +73,14 @@ final class AesCbcWithIntegrity {
private static final int PBE_SALT_LENGTH_BITS = AES_KEY_LENGTH_BITS; // same size as key output
private static final String PBE_ALGORITHM = "PBKDF2WithHmacSHA1";
private static final int BASE64_FLAGS = Base64.NO_WRAP;
- private static final AtomicBoolean prngFixed = new AtomicBoolean(false);
+ private static final AtomicBoolean PRNG_FIXED = new AtomicBoolean(false);
private static final String HMAC_ALGORITHM = "HmacSHA256";
private static final int HMAC_KEY_LENGTH_BITS = 256;
+ private AesCbcWithIntegrity() {
+ //no instance
+ }
+
/**
* Converts the given AES/HMAC keys into a base64 encoded string suitable for
* storage. Sister function of keys.
@@ -136,7 +140,7 @@ public static SecretKeys generateKey() throws GeneralSecurityException {
SecretKey confidentialityKey = keyGen.generateKey();
//Now make the HMAC key
- byte[] integrityKeyBytes = randomBytes(HMAC_KEY_LENGTH_BITS / 8);//to get bytes
+ byte[] integrityKeyBytes = randomBytes(HMAC_KEY_LENGTH_BITS / 8); //to get bytes
SecretKey integrityKey = new SecretKeySpec(integrityKeyBytes, HMAC_ALGORITHM);
return new SecretKeys(confidentialityKey, integrityKey);
@@ -162,7 +166,9 @@ public static SecretKeys generateKeyFromPassword(String password, byte[] salt) t
// Split the random bytes into two parts:
byte[] confidentialityKeyBytes = copyOfRange(keyBytes, 0, AES_KEY_LENGTH_BITS / 8);
- byte[] integrityKeyBytes = copyOfRange(keyBytes, AES_KEY_LENGTH_BITS / 8, AES_KEY_LENGTH_BITS / 8 + HMAC_KEY_LENGTH_BITS / 8);
+ byte[] integrityKeyBytes = copyOfRange(
+ keyBytes, AES_KEY_LENGTH_BITS / 8, AES_KEY_LENGTH_BITS / 8 + HMAC_KEY_LENGTH_BITS / 8
+ );
//Generate the AES key
SecretKey confidentialityKey = new SecretKeySpec(confidentialityKeyBytes, CIPHER);
@@ -237,7 +243,7 @@ private static byte[] copyOfRange(byte[] from, int start, int end) {
System.arraycopy(from, start, result, 0, length);
return result;
}
-
+
/*
* -----------------------------------------------------------------
* Encryption
@@ -307,11 +313,11 @@ public static CipherTextIvMac encrypt(byte[] plaintext, SecretKeys secretKeys)
* Will only run once, and every subsequent call should return immediately.
*/
private static void fixPrng() {
- if (!prngFixed.get()) {
+ if (!PRNG_FIXED.get()) {
synchronized (PrngFixes.class) {
- if (!prngFixed.get()) {
+ if (!PRNG_FIXED.get()) {
PrngFixes.apply();
- prngFixed.set(true);
+ PRNG_FIXED.set(true);
}
}
}
@@ -391,11 +397,12 @@ public static byte[] decrypt(CipherTextIvMac civ, SecretKeys secretKeys)
* @throws java.security.NoSuchAlgorithmException
* @throws java.security.InvalidKeyException
*/
- public static byte[] generateMac(byte[] byteCipherText, SecretKey integrityKey) throws NoSuchAlgorithmException, InvalidKeyException {
+ public static byte[] generateMac(byte[] byteCipherText, SecretKey integrityKey)
+ throws NoSuchAlgorithmException, InvalidKeyException {
//Now compute the mac for later integrity checking
- Mac sha256_HMAC = Mac.getInstance(HMAC_ALGORITHM);
- sha256_HMAC.init(integrityKey);
- return sha256_HMAC.doFinal(byteCipherText);
+ Mac sha256HMAC = Mac.getInstance(HMAC_ALGORITHM);
+ sha256HMAC.init(integrityKey);
+ return sha256HMAC.doFinal(byteCipherText);
}
/**
@@ -759,7 +766,7 @@ public static class LinuxPRNGSecureRandom extends SecureRandomSpi {
private static final File URANDOM_FILE = new File("/dev/urandom");
- private static final Object sLock = new Object();
+ private static final Object LOCK = new Object();
/**
* Input stream for reading from Linux PRNG or {@code null} if not
@@ -788,7 +795,7 @@ public static class LinuxPRNGSecureRandom extends SecureRandomSpi {
protected void engineSetSeed(byte[] bytes) {
try {
OutputStream out;
- synchronized (sLock) {
+ synchronized (LOCK) {
out = getUrandomOutputStream();
}
out.write(bytes);
@@ -812,7 +819,7 @@ protected void engineNextBytes(byte[] bytes) {
try {
DataInputStream in;
- synchronized (sLock) {
+ synchronized (LOCK) {
in = getUrandomInputStream();
}
synchronized (in) {
@@ -831,7 +838,7 @@ protected byte[] engineGenerateSeed(int size) {
}
private DataInputStream getUrandomInputStream() {
- synchronized (sLock) {
+ synchronized (LOCK) {
if (sUrandomIn == null) {
// NOTE: Consider inserting a BufferedInputStream
// between DataInputStream and FileInputStream if you need
@@ -849,7 +856,7 @@ private DataInputStream getUrandomInputStream() {
}
private OutputStream getUrandomOutputStream() throws IOException {
- synchronized (sLock) {
+ synchronized (LOCK) {
if (sUrandomOut == null) {
sUrandomOut = new FileOutputStream(URANDOM_FILE);
}
diff --git a/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java b/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java
index d5a99cb..3f8ed24 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java
@@ -7,8 +7,6 @@
/**
* Provides AES algorithm
- *
- * @author Orhan Obut
*/
final class AesEncryption implements Encryption {
diff --git a/hawk/src/main/java/com/orhanobut/hawk/DataHelper.java b/hawk/src/main/java/com/orhanobut/hawk/DataHelper.java
index af4b625..bca06f5 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/DataHelper.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/DataHelper.java
@@ -9,9 +9,6 @@
import java.util.Map;
import java.util.Set;
-/**
- * @author Orhan Obut
- */
final class DataHelper {
private static final String DELIMITER = "@";
@@ -21,13 +18,13 @@ final class DataHelper {
@Deprecated
private static final char FLAG_SERIALIZABLE = '1';
- private static final Map typeMap = new HashMap<>();
+ private static final Map TYPE_MAP = new HashMap<>();
static {
- typeMap.put(DataType.OBJECT.getType(), DataType.OBJECT);
- typeMap.put(DataType.LIST.getType(), DataType.LIST);
- typeMap.put(DataType.MAP.getType(), DataType.MAP);
- typeMap.put(DataType.SET.getType(), DataType.SET);
+ TYPE_MAP.put(DataType.OBJECT.getType(), DataType.OBJECT);
+ TYPE_MAP.put(DataType.LIST.getType(), DataType.LIST);
+ TYPE_MAP.put(DataType.MAP.getType(), DataType.MAP);
+ TYPE_MAP.put(DataType.SET.getType(), DataType.SET);
}
private DataHelper() {
@@ -67,7 +64,7 @@ static DataInfo getNewDataInfo(String text, String cipherText) {
String[] infos = text.split(INFO_DELIMITER);
char type = infos[2].charAt(0);
- DataType dataType = typeMap.get(type);
+ DataType dataType = TYPE_MAP.get(type);
// if it is collection, no need to create the class object
Class> keyClazz = null;
@@ -95,7 +92,7 @@ static DataInfo getNewDataInfo(String text, String cipherText) {
static DataInfo getOldDataInfo(String text, String cipherText) {
boolean serializable = text.charAt(text.length() - 1) == FLAG_SERIALIZABLE;
char type = text.charAt(text.length() - 2);
- DataType dataType = typeMap.get(type);
+ DataType dataType = TYPE_MAP.get(type);
String className = text.substring(0, text.length() - 2);
diff --git a/hawk/src/main/java/com/orhanobut/hawk/DataInfo.java b/hawk/src/main/java/com/orhanobut/hawk/DataInfo.java
index a02e951..45242bd 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/DataInfo.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/DataInfo.java
@@ -1,8 +1,5 @@
package com.orhanobut.hawk;
-/**
- * @author Orhan Obut
- */
final class DataInfo {
private final DataType dataType;
diff --git a/hawk/src/main/java/com/orhanobut/hawk/DataType.java b/hawk/src/main/java/com/orhanobut/hawk/DataType.java
index 1988e63..04e19d4 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/DataType.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/DataType.java
@@ -1,8 +1,5 @@
package com.orhanobut.hawk;
-/**
- * @author Orhan Obut
- */
enum DataType {
OBJECT('0'),
LIST('1'),
diff --git a/hawk/src/main/java/com/orhanobut/hawk/Encoder.java b/hawk/src/main/java/com/orhanobut/hawk/Encoder.java
index 63de74b..6e77a56 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/Encoder.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/Encoder.java
@@ -1,8 +1,5 @@
package com.orhanobut.hawk;
-/**
- * @author Orhan Obut
- */
interface Encoder {
/**
diff --git a/hawk/src/main/java/com/orhanobut/hawk/Encryption.java b/hawk/src/main/java/com/orhanobut/hawk/Encryption.java
index cf62893..f007bf8 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/Encryption.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/Encryption.java
@@ -1,8 +1,5 @@
package com.orhanobut.hawk;
-/**
- * @author Orhan Obut
- */
interface Encryption {
/**
diff --git a/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java b/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java
index 7dffbac..0ced1eb 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java
@@ -7,9 +7,6 @@
import java.lang.reflect.Type;
-/**
- * @author Orhan Obut
- */
final class GsonParser implements Parser {
private final Gson gson;
diff --git a/hawk/src/main/java/com/orhanobut/hawk/Hawk.java b/hawk/src/main/java/com/orhanobut/hawk/Hawk.java
index 4b70f29..41e9dae 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/Hawk.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/Hawk.java
@@ -10,9 +10,6 @@
import rx.Observable;
import rx.Subscriber;
-/**
- * @author Orhan Obut
- */
public final class Hawk {
private static HawkBuilder hawkBuilder;
diff --git a/hawk/src/main/java/com/orhanobut/hawk/HawkBuilder.java b/hawk/src/main/java/com/orhanobut/hawk/HawkBuilder.java
index 6b27ae6..10ca65f 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/HawkBuilder.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/HawkBuilder.java
@@ -8,13 +8,8 @@
import rx.Observable;
import rx.Subscriber;
-import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func0;
-import rx.schedulers.Schedulers;
-/**
- * @author Orhan Obut
- */
public class HawkBuilder {
/**
@@ -191,6 +186,8 @@ private void setEncryption() {
encryptionMethod = EncryptionMethod.NO_ENCRYPTION;
}
break;
+ default:
+ throw new IllegalStateException("Encryption mode is not correct");
}
}
@@ -233,6 +230,6 @@ public void call(Subscriber super Boolean> subscriber) {
}
});
}
- }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
+ });
}
}
diff --git a/hawk/src/main/java/com/orhanobut/hawk/HawkEncoder.java b/hawk/src/main/java/com/orhanobut/hawk/HawkEncoder.java
index 5c5b8ff..0c10105 100644
--- a/hawk/src/main/java/com/orhanobut/hawk/HawkEncoder.java
+++ b/hawk/src/main/java/com/orhanobut/hawk/HawkEncoder.java
@@ -17,8 +17,6 @@
* List types will be encoded/decoded by parser
* Serializable types will be encoded/decoded object stream
* Not serializable objects will be encoded/decoded by parser
- *
- * @author Orhan Obut
*/
final class HawkEncoder implements Encoder {
@@ -97,8 +95,9 @@ private T decodeNew(byte[] bytes, DataInfo info) throws Exception {
return toMap(json, keyType, valueType);
case SET:
return toSet(json, keyType);
+ default:
+ return null;
}
- return null;
}
private T toObject(String json, Class> type) throws Exception {
@@ -110,8 +109,11 @@ private T toList(String json, Class> type) throws Exception {
if (type == null) {
return (T) new ArrayList<>();
}
- List list = parser.fromJson(json, new TypeToken>() {
- }.getType());
+ List list = parser.fromJson(
+ json,
+ new TypeToken>() {
+ } .getType()
+ );
int size = list.size();
for (int i = 0; i < size; i++) {
@@ -127,7 +129,7 @@ private T toSet(String json, Class> type) throws Exception {
return (T) resultSet;
}
Set set = parser.fromJson(json, new TypeToken>() {
- }.getType());
+ } .getType());
for (T t : set) {
String valueJson = parser.toJson(t);
@@ -144,7 +146,7 @@ private T toMap(String json, Class> keyType, Class> valueType) thr
return (T) resultMap;
}
Map map = parser.fromJson(json, new TypeToken