diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b0db11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/.idea +/.idea/* +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build diff --git a/README.md b/README.md new file mode 100644 index 0000000..893c562 --- /dev/null +++ b/README.md @@ -0,0 +1,109 @@ +![image](/images/hypercube.png =100x) +#WaspDb +WaspDB is a pure Java key/value (NoSQL) database library for Android. It supports AES256 encryption for all the disk storage. It's very small (the aar file is ~189 KB). + +Keys and Values are simple Java Objects. Everything is automatically serialized using the [Kryo]() serialization library. + +Data is stored by an implementation of hashmaps on disk. + + +###QuickStart + +To use it with gradle + + dependencies { + compile 'REPLACEME' + } + +Let's assume a POJO (even with nested object, like Address): + + class User { + private String username; + private String email; + private String telephone; + private Address address; + + public User() { + } + + // getters and setters... + } + +No need to be Serializable or Parcelable or annotations or extending/implementing from other classes/interfaces, the only important thing is to have an **empty constructor**. + +**Create a database, a WaspHash and store a POJO** + + // create a database, using the default files dir as path, database name and a password + String path = getFilesDir().getPath(); + String databaseName = "myDb"; + String password = "passw0rd"; + + WaspDb db = WaspFactory.openOrCreateDatabase(path,databaseName,password); + + // now create an WaspHash, it's like a sql table + WaspHash users = db.openOrCreateHash("users"); + + // now let's have a POJO + User p = new User(); + ... // do your stuff with your POJO! + + // and simply store it! + users.put(p.getUsername(), p); + + +**To retrieve it**, it's just + + User p = users.get("username1"); + +**Need all your objects?** + + List allUsers = users.getAllValues(); + +It returns all the users, in a standard java List. + +Or you can **get all the keys** used + + List keys = users.getAllKeys(); + +or the actual **key/value map** (it's again a standard java class) + + HashMap usersMap = users.getAllData(); + +Please note that the process of creating an encrypted database is computationally expensive (10000 iterations to create the AES256 key), so also an async method is available: + + WaspFactory.openOrCreateDatabase(path, databaseName, password, new WaspListener() { + @Override + public void onDone(WaspDb waspDb) { + .... + } + }); + + +###Why WaspDb +I **hate** to store objects on sqlite! It's a lot of boiler code...for what? +Okay, let's say in the polite way :) + + The object-relational impedance mismatch is a set of conceptual and technical difficulties that are often encountered when a relational database management system (RDBMS) is being used by a program written in an object-oriented programming language or style; particularly when objects or class definitions are mapped in a straightforward way to database tables or relational schema. +(from wikipedia [https://en.wikipedia.org/wiki/Object-relational_impedance_mismatch](https://en.wikipedia.org/wiki/Object-relational_impedance_mismatch)) + +###What WaspDb is NOT +This is not a SQL database. It does not have a relational data model, it does not support SQL queries, and it provides no support for indexes, nor transactions. + +###Features +- it's pure java, it's standalone, no native stuff, it's not an ORM to SqlLite! + +- the database addresses up to 4294967296 keys for WaspHash...enough? :) + +###Limitations +- it's NOT transactional. So if you wanna store 10000, it will make 10000 actual write operations to disk in sequence. That means it will be slower (in this case) compared to transactional databases. (of course, if you store 100 items as a java List - so actually a single object - it will make a single(ish) write operation) + + +###Performances + +I've used this project [https://github.com/Raizlabs/AndroidDatabaseLibraryComparison](https://github.com/Raizlabs/AndroidDatabaseLibraryComparison) to make some benchmarking. + +This is the "simple trial" (storing 50 objects) on a Nexus 5, using WaspDb's encryption feature: + +![image](/images/wasp_comparison.png =800x) + +It's even faster if you don't need encryption. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..ec0a61d --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "net.rehacktive.waspdbexample" + minSdkVersion 14 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + + lintOptions { + abortOnError false + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:22.0.0' + compile project(':waspdb') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..dfe9ea7 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/stefano/android-sdk-macosx/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/net/rehacktive/waspdbexample/ApplicationTest.java b/app/src/androidTest/java/net/rehacktive/waspdbexample/ApplicationTest.java new file mode 100644 index 0000000..46ef286 --- /dev/null +++ b/app/src/androidTest/java/net/rehacktive/waspdbexample/ApplicationTest.java @@ -0,0 +1,13 @@ +package net.rehacktive.waspdbexample; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ac1f030 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/net/rehacktive/waspdbexample/MainActivity.java b/app/src/main/java/net/rehacktive/waspdbexample/MainActivity.java new file mode 100644 index 0000000..a5cf240 --- /dev/null +++ b/app/src/main/java/net/rehacktive/waspdbexample/MainActivity.java @@ -0,0 +1,120 @@ +package net.rehacktive.waspdbexample; + +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.ListView; +import android.widget.ProgressBar; + +import net.rehacktive.waspdb.WaspDb; +import net.rehacktive.waspdb.WaspFactory; +import net.rehacktive.waspdb.WaspHash; +import net.rehacktive.waspdb.WaspListener; +import net.rehacktive.waspdb.WaspObserver; + +import java.util.ArrayList; +import java.util.List; + +public class MainActivity extends ActionBarActivity { + + ProgressBar progressBar; + // wasp objects + WaspDb db; + WaspHash hash; + WaspObserver observer; + + UserAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + progressBar = (ProgressBar) findViewById(R.id.progressBar); + + ListView userList = (ListView) findViewById(R.id.userlist); + adapter = new UserAdapter(this); + userList.setAdapter(adapter); + + if(db==null) { + progressBar.setVisibility(View.VISIBLE); + WaspFactory.openOrCreateDatabase(getFilesDir().getPath(), "example", "Passw0rd", new WaspListener() { + @Override + public void onDone(WaspDb waspDb) { + db = waspDb; + hash = db.openOrCreateHash("users"); + + progressBar.setVisibility(View.INVISIBLE); + + getUsers(); + + observer = new WaspObserver() { + @Override + public void onChange() { + List users = hash.getAllValues(); + adapter.setUsers(users); + adapter.notifyDataSetChanged(); + } + }; + + hash.register(observer); + } + }); + } + } + + private void getUsers() { + List users = hash.getAllValues(); + if(users==null) + users = new ArrayList<>(); + + adapter.setUsers(users); + adapter.notifyDataSetChanged(); + } + + private void addUser() { + User user = new User("user "+System.currentTimeMillis(), ""); + hash.put(user.getUser_name(),user); + } + + private void flushUsers() { + hash.flush(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + hash.unregister(observer); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.add_user) { + addUser(); + return true; + } + + if (id == R.id.flush_user) { + flushUsers(); + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/net/rehacktive/waspdbexample/User.java b/app/src/main/java/net/rehacktive/waspdbexample/User.java new file mode 100644 index 0000000..094f26c --- /dev/null +++ b/app/src/main/java/net/rehacktive/waspdbexample/User.java @@ -0,0 +1,44 @@ +package net.rehacktive.waspdbexample; + +/** + * Created by stefano on 28/07/2015. + */ +public class User { + + private String id; + private String user_name; + private String email; + + public User() { + } + + public User(String username, String email) { + this.user_name = username; + this.email = email; + this.id = ""+System.currentTimeMillis(); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUser_name() { + return user_name; + } + + public void setUser_name(String user_name) { + this.user_name = user_name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/app/src/main/java/net/rehacktive/waspdbexample/UserAdapter.java b/app/src/main/java/net/rehacktive/waspdbexample/UserAdapter.java new file mode 100644 index 0000000..eb6ce33 --- /dev/null +++ b/app/src/main/java/net/rehacktive/waspdbexample/UserAdapter.java @@ -0,0 +1,73 @@ +package net.rehacktive.waspdbexample; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import java.util.List; + +/** + * Created by stefano on 31/07/2015. + */ +public class UserAdapter extends BaseAdapter { + + private List users; + + LayoutInflater mInflator; + + Context mContext; + + public UserAdapter(Context context) { + mContext = context; + mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + public void setUsers(List users) { + this.users = users; + } + + @Override + public int getCount() { + return users != null ? users.size() : 0; + } + + @Override + public User getItem(int i) { + return users.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int position, View convertView, ViewGroup container) { + + Viewholder holder; + + final User t = getItem(position); + + if (convertView == null) { + holder = new Viewholder(); + convertView = mInflator.inflate(R.layout.row_user, container, false); + holder.username = (TextView) convertView.findViewById(R.id.username); + convertView.setTag(holder); + + } else { + holder = (Viewholder) convertView.getTag(); + } + + holder.username.setText(t.getUser_name()); + + return convertView; + } + + private class Viewholder { + TextView username; + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..89852b1 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/app/src/main/res/layout/row_user.xml b/app/src/main/res/layout/row_user.xml new file mode 100644 index 0000000..4d60091 --- /dev/null +++ b/app/src/main/res/layout/row_user.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..a78bf7f --- /dev/null +++ b/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..8f79128 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,6 @@ + + WaspDbExample + + Hello world! + Settings + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e6c1aa5 --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.3' + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1d3591c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +# 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 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..8c0fb64 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..274bee0 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Jul 27 17:20:00 BST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/images/hypercube.png b/images/hypercube.png new file mode 100644 index 0000000..9ec41fa Binary files /dev/null and b/images/hypercube.png differ diff --git a/images/wasp_comparison.png b/images/wasp_comparison.png new file mode 100644 index 0000000..03565cb Binary files /dev/null and b/images/wasp_comparison.png differ diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..a8617fe --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app', ':waspdb' diff --git a/waspdb/.gitignore b/waspdb/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/waspdb/.gitignore @@ -0,0 +1 @@ +/build diff --git a/waspdb/build.gradle b/waspdb/build.gradle new file mode 100644 index 0000000..2cc2cad --- /dev/null +++ b/waspdb/build.gradle @@ -0,0 +1,60 @@ +apply plugin: 'com.android.library' + +buildscript { + repositories { + jcenter() + } +} + +android { + packagingOptions { + exclude 'META-INF/DEPENDENCIES.txt' + exclude 'META-INF/LICENSE.txt' + exclude 'META-INF/NOTICE.txt' + exclude 'META-INF/NOTICE' + exclude 'META-INF/LICENSE' + exclude 'META-INF/DEPENDENCIES' + exclude 'META-INF/notice.txt' + exclude 'META-INF/license.txt' + exclude 'META-INF/dependencies.txt' + exclude 'META-INF/LGPL2.1' + } + + compileSdkVersion 22 + buildToolsVersion "21.1.2" + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + + lintOptions { + abortOnError false + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + buildTypes { + debug { + buildConfigField "boolean", "IS_DEBUG", "true" + } + + release { + minifyEnabled false + buildConfigField "boolean", "IS_DEBUG", "false" + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.esotericsoftware:kryo:3.0.3' +} + + + + diff --git a/waspdb/libs/commons-io-2.4.jar b/waspdb/libs/commons-io-2.4.jar new file mode 100644 index 0000000..8377504 Binary files /dev/null and b/waspdb/libs/commons-io-2.4.jar differ diff --git a/waspdb/proguard-rules.pro b/waspdb/proguard-rules.pro new file mode 100644 index 0000000..dfe9ea7 --- /dev/null +++ b/waspdb/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/stefano/android-sdk-macosx/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/waspdb/src/androidTest/java/net/rehacktive/waspdb/MainTest.java b/waspdb/src/androidTest/java/net/rehacktive/waspdb/MainTest.java new file mode 100644 index 0000000..22d3b0e --- /dev/null +++ b/waspdb/src/androidTest/java/net/rehacktive/waspdb/MainTest.java @@ -0,0 +1,175 @@ +package net.rehacktive.waspdb; + +import android.content.Context; +import android.test.InstrumentationTestCase; +import android.util.Log; + +import java.util.HashMap; +import java.util.List; + +/** + * Created by stefano on 30/07/2015. + */ +public class MainTest extends InstrumentationTestCase { + + String path; + String dbName = "justAtestDb"; + String dbPwd = "passw0rd!"; + + Context ctx; + + WaspDb db; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ctx = getInstrumentation().getContext(); + path = ctx.getFilesDir().getAbsolutePath(); + + db = WaspFactory.openOrCreateDatabase(path,dbName,dbPwd); + } + + public void testDatabaseCreation() { + WaspFactory.openOrCreateDatabase(path, dbName, dbPwd, new WaspListener() { + @Override + public void onDone(WaspDb ret) { + assertTrue("testDatabaseCreation", WaspFactory.existsDatabase(path, dbName)); + } + }); + + } + + public void testCreateHash() throws Exception { + db.openOrCreateHash("hash"); + assertTrue("testCreateHash", db.existsHash("hash")); + } + + public void testPut() throws Exception { + int id = 1; + UserWithNestedContent p = new UserWithNestedContent(id, "test", "123"); + WaspHash hash = db.openOrCreateHash("hash"); + hash.flush(); + + hash.put(id, p); + + UserWithNestedContent newPerson = hash.get(id); + assertTrue("testPut", newPerson.equals(p) && newPerson.getFriends().size()==UserWithNestedContent.NUMBER_OF_FRIENDS); + } + + public void testMultiplePut() throws Exception { + WaspHash hash = db.openOrCreateHash("test12"); + hash.flush(); + + Long start = System.currentTimeMillis(); + int count = 100; + for (int i = 0; i < count; i++) { + UserWithNestedContent user = new UserWithNestedContent(i, "b" + i, ""); + hash.put(user.getUsername(), user); + } + Long end = System.currentTimeMillis(); + Log.d("WASPDEBUG MULTIPLE",(end-start)+" ms"); + List result = hash.getAllKeys(); + Long end2 = System.currentTimeMillis(); + Log.d("WASPDEBUG MULTIPLE",(end2-end)+" ms for reading all"); + assertTrue("testMultiplePut " + result.size(), result.size() == count); + } + + public void testGetAllKeys() throws Exception { + WaspHash hash = db.openOrCreateHash("users"); + hash.flush(); + + int count = 10; + for(int i=0; i result = hash.getAllKeys(); + assertTrue("testGetAllKeys", result.size() == count); + } + + public void testGetAllValues() throws Exception { + WaspHash hash = db.openOrCreateHash("users"); + hash.flush(); + + int count = 10; + for(int i=0; i result = hash.getAllValues(); + assertTrue("testGetAllValues", result.size() == count); + } + + public void testGetAllData() throws Exception { + WaspHash hash = db.openOrCreateHash("users"); + hash.flush(); + + int count = 10; + for(int i=0; i result = hash.getAllData(); + assertTrue("testGetAllData", result.size() == count); + } + + public void testRemove() throws Exception { + WaspHash hash = db.openOrCreateHash("deleteHash"); + + UserWithNestedContent p = new UserWithNestedContent(1,"test","123"); + + hash.put(1,p); + + hash.remove(1); + + assertTrue("testDelete", hash.getAllKeys().size() == 0); + } + + public void testHashFlush() throws Exception { + WaspHash hash = db.openOrCreateHash("anotherHash"); + + UserWithNestedContent p = new UserWithNestedContent(1,"test","123"); + + hash.put(1,p); + + hash.flush(); + + assertTrue("testHashFlush", hash.getAllKeys().size() == 0); + } + + public void testHashDelete() throws Exception { + WaspHash hash = db.openOrCreateHash("anotherHashToDelete"); + if(hash!=null) { + db.removeHash("anotherHashToDelete"); + assertTrue(!db.existsHash("anotherHashToDelete")); + } else { + fail(); + } + } + + public void testDatabaseDestroy() throws Exception { + // TODO + } + + public void testObserver() throws Exception { + int id = 2; + UserWithNestedContent p = new UserWithNestedContent(id,"test","123"); + + final WaspHash hash = db.openOrCreateHash("another_hash"); + hash.flush(); + + hash.register(new WaspObserver() { + @Override + public void onChange() { + assertTrue("testObserver", hash.getAllKeys().size() == 1); + } + }); + + hash.put(id, p); + } + + +} diff --git a/waspdb/src/androidTest/java/net/rehacktive/waspdb/User.java b/waspdb/src/androidTest/java/net/rehacktive/waspdb/User.java new file mode 100644 index 0000000..32f2a93 --- /dev/null +++ b/waspdb/src/androidTest/java/net/rehacktive/waspdb/User.java @@ -0,0 +1,68 @@ +package net.rehacktive.waspdb; + +/** + * Created by stefano on 17/03/2015. + */ +public class User { + + private int id; + private String username; + private String telephone; + + public User() { + } + + public User(int id, String username, String telephone) { + this.id = id; + this.username = username; + this.telephone = telephone; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + User user = (User) o; + + if (id != user.id) return false; + if (telephone != null ? !telephone.equals(user.telephone) : user.telephone != null) + return false; + if (username != null ? !username.equals(user.username) : user.username != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + (username != null ? username.hashCode() : 0); + result = 31 * result + (telephone != null ? telephone.hashCode() : 0); + return result; + } +} diff --git a/waspdb/src/androidTest/java/net/rehacktive/waspdb/UserWithNestedContent.java b/waspdb/src/androidTest/java/net/rehacktive/waspdb/UserWithNestedContent.java new file mode 100644 index 0000000..6070e31 --- /dev/null +++ b/waspdb/src/androidTest/java/net/rehacktive/waspdb/UserWithNestedContent.java @@ -0,0 +1,96 @@ +package net.rehacktive.waspdb; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by stefano on 17/03/2015. + */ +public class UserWithNestedContent { + + public static int NUMBER_OF_FRIENDS = 20; + + private int id; + private String username; + private String telephone; + private List friends; + + public UserWithNestedContent() { + } + + public UserWithNestedContent(int id, String username, String telephone) { + this.id = id; + this.username = username; + this.telephone = telephone; + // generate list of friends + this.friends = new ArrayList<>(); + for (int i = 0; i < NUMBER_OF_FRIENDS; i++) { + User p = new User(i, "test"+i, "123"); + friends.add(p); + } + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + + public List getFriends() { + return friends; + } + + public void setFriends(List friends) { + this.friends = friends; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UserWithNestedContent person = (UserWithNestedContent) o; + + if (id != person.id) return false; + if (telephone != null ? !telephone.equals(person.telephone) : person.telephone != null) + return false; + if (username != null ? !username.equals(person.username) : person.username != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + (username != null ? username.hashCode() : 0); + result = 31 * result + (telephone != null ? telephone.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "UserWithNestedContent{" + + "id=" + id + + ", username='" + username + '\'' + + '}'; + } +} diff --git a/waspdb/src/main/AndroidManifest.xml b/waspdb/src/main/AndroidManifest.xml new file mode 100644 index 0000000..fde3ddf --- /dev/null +++ b/waspdb/src/main/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/WaspDb.java b/waspdb/src/main/java/net/rehacktive/waspdb/WaspDb.java new file mode 100755 index 0000000..356dad9 --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/WaspDb.java @@ -0,0 +1,190 @@ +package net.rehacktive.waspdb; + +import net.rehacktive.waspdb.internals.cryptolayer.CipherManager; +import net.rehacktive.waspdb.internals.utils.Utils; + +import java.io.File; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; + +public class WaspDb { + + /* + * this object contains all main infos about database + * this file is "kryonized" under {path}/dbname/db.data + */ + + private String dbName; // db name + private String path; // db path + private CipherManager cipherManager; + + private List hashes; // all hashes used + + protected WaspDb() { + } + + /** + * Open/create a WaspHash instance + * @param hashName name + * @return + */ + public WaspHash openOrCreateHash(String hashName) { + WaspHash hash; + try { + if(existsHash(hashName)) { + hash = getHash(hashName); + } else { + hash = createHash(hashName); + } + return hash; + } + catch(Exception wfe) { + wfe.printStackTrace(); + return null; + } + } + + /** + * Check if the WaspHash exists + * @param hashName name + * @return + */ + public boolean existsHash(String hashName) { + try { + String realname = Utils.md5(hashName); + String directory = path+"/"+Utils.md5(dbName)+"/"+realname; + return new File(directory).exists(); + } + catch(Exception e) { + return false; + } + } + + protected WaspHash getHash(String hashName) { + try { + String realname = Utils.md5(hashName); + String directory = path+"/"+Utils.md5(dbName)+"/"+realname; + if(new File(directory).exists()) { // already exists + WaspHash hash = new WaspHash(cipherManager,directory); + return hash; + } + else { + return null; + } + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + protected WaspHash createHash(String hashName) { + try { + String realname = Utils.md5(hashName); + String directory = path+"/"+Utils.md5(dbName)+"/"+realname; + if(!new File(directory).exists()) { // if not exists + // create a new one + if(new File(directory).mkdir()) { + WaspHash hash = new WaspHash(cipherManager,directory); + + if(hashes==null) hashes = new ArrayList(); + hashes.add(hashName); + persist(); // update db data on disk + return hash; + } + else { + return null; + } + } else { + return getHash(hashName); + } + } catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Delete the specified WaspHash + * @param hashName name + * @return + */ + public boolean removeHash(String hashName) { + try { + String realname = Utils.md5(hashName); + String directory = path+"/"+Utils.md5(dbName)+"/"+realname; + if(new File(directory).exists()) { // if exists + // delete recursively + try { + Utils.deleteRecursive(new File(directory)); + + if(hashes!=null) hashes.remove(hashName); + persist(); // update db data on disk + + return true; + } + catch(Exception e) { + return false; + } + } else { + return false; + } + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * Return a list of all WaspHash names associated to this database + * @return + */ + public List getAllHashes() { + return hashes; + } + + protected String getName() throws NoSuchAlgorithmException { + return Utils.md5(dbName); + } + + protected void setName(String name) { + this.dbName = name; + } + + protected String getPath() { + return path; + } + + protected void setPath(String path) { + this.path = path; + } + + /** + * Get information about this instance + * @return a string containing some information + */ + @Override + public String toString() { + return "WaspDb [name=" + dbName + ", path=" + path + ", cipher enabled = " + + (cipherManager!=null) + "]"; + } + + private void persist() { + WaspFactory.storeDatabase(this, cipherManager); + } + + protected CipherManager getCipherManager() { + return cipherManager; + } + + protected void setCipherManager(CipherManager cm) { + this.cipherManager = cm; + } + + protected void clearCipherInformation() { + this.cipherManager = null; + } + + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/WaspFactory.java b/waspdb/src/main/java/net/rehacktive/waspdb/WaspFactory.java new file mode 100755 index 0000000..2661f2f --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/WaspFactory.java @@ -0,0 +1,178 @@ +package net.rehacktive.waspdb; + +import android.os.AsyncTask; + +import net.rehacktive.waspdb.internals.collision.KryoStoreUtils; +import net.rehacktive.waspdb.internals.cryptolayer.CipherManager; +import net.rehacktive.waspdb.internals.utils.Salt; +import net.rehacktive.waspdb.internals.utils.Utils; + +import java.io.File; + +public class WaspFactory { + + private static final String DB_NAME = "data.db"; + private static final String SALT_NAME = "salt"; + + /** + * Asynchronously open/create a WaspDb instance + * the operation requires some time, according to device CPU power + * @param path the path for the database folder - use Context.getFilesDir().getPath() + * @param name name of the database + * @param password password - set as null if you don't need encryption / for better performances + * @param listener a WaspListener instance, to get the database when is ready + */ + public static void openOrCreateDatabase(final String path, final String name, final String password, final WaspListener listener) { + new AsyncTask() { + + WaspDb db = null; + + @Override + protected Void doInBackground(Void... params) { + if(WaspFactory.existsDatabase(path, name)) { + db = WaspFactory.loadDatabase(path, name, password); + } else { + db = WaspFactory.createDatabase(path, name, password); + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if(db!=null) { + listener.onDone(db); + } else { + listener.onError("error on openOrCreateDatabase"); + } + } + }.execute(); + + } + + /** + * Synchronous call to create the database - use outside of the main thread! + * @param path the path for the database folder - use Context.getFilesDir().getPath() + * @param name name of the database + * @param password password - set as null if you don't need encryption / for better performances + * @return + */ + public static WaspDb openOrCreateDatabase(String path, String name, String password) { + if(WaspFactory.existsDatabase(path, name)) { + return WaspFactory.loadDatabase(path, name, password); + } else { + return WaspFactory.createDatabase(path, name, password); + } + } + + /** + * Destroy the database and remove all the data + * @param db the database object to destroy + * @return + */ + public static boolean destroyDatabase(WaspDb db) { + try { + String directory = db.getPath()+"/"+Utils.md5(db.getName())+"/"; + if(new File(directory).exists()) { // if exists + // delete recursively + try { + Utils.deleteRecursive(new File(directory)); + return true; + } + catch(Exception e) { + return false; + } + } else { + return true; + } + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + + // PROTECTED + + protected static boolean existsDatabase(String path, String name) { + try { + WaspDb db = new WaspDb(); + db.setPath(path); + db.setName(name); + String directory; + directory = db.getPath()+"/"+db.getName(); + + return (new File(directory).exists()); + } catch (Exception e) { + return false; + } + } + + protected static WaspDb createDatabase(final String path, final String name, final String password) { + if(password!=null && !Utils.checkForCryptoAvailable()) return null; + Salt salt = Utils.generateSalt(); + WaspDb db = new WaspDb(); + db.setName(name); + db.setPath(path); + try { + CipherManager cipherManager = null; + if (!Utils.isEmpty(password)) { + cipherManager = CipherManager.getInstance(password.toCharArray(), salt.getSalt()); + } + + boolean ret = storeDatabase(db, cipherManager); + if (ret) { + KryoStoreUtils.serializeToDisk(salt, db.getPath()+"/"+db.getName()+"/"+SALT_NAME, null); + db.setCipherManager(cipherManager); // set the ciphermanager in the object + return db; + } else return null; + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + protected static boolean storeDatabase(WaspDb db, CipherManager cipherManager) { + try { + String directory = db.getPath()+"/"+db.getName(); + //if((new File(directory).exists())) throw new WaspFatalException("database already exists"); + boolean success = true; + if(!(new File(directory).exists())) success = (new File(directory)).mkdir(); + if(success) { + // do not store the cipherManager + db.clearCipherInformation(); + KryoStoreUtils.serializeToDisk(db, db.getPath() + "/" + db.getName() + "/" + DB_NAME, cipherManager); + db.setCipherManager(cipherManager); + + return true; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + protected static WaspDb loadDatabase(final String path, final String name, final String password) { + if(password!=null && !Utils.checkForCryptoAvailable()) return null; + CipherManager cipherManager = null; + try { + String realname = Utils.md5(name); + WaspDb db; + + Salt salt = (Salt) KryoStoreUtils.readFromDisk(path + "/" + realname +"/"+SALT_NAME,Salt.class, null); + if(!Utils.isEmpty(password)) + cipherManager = CipherManager.getInstance(password.toCharArray(),salt.getSalt()); + db = (WaspDb) KryoStoreUtils.readFromDisk(path + "/" + realname + "/" + DB_NAME, WaspDb.class, cipherManager); + + db.setPath(path); // refresh the path to the current one + db.setCipherManager(cipherManager); // set the password in the object + return db; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/WaspHash.java b/waspdb/src/main/java/net/rehacktive/waspdb/WaspHash.java new file mode 100755 index 0000000..481293f --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/WaspHash.java @@ -0,0 +1,162 @@ +package net.rehacktive.waspdb; + +import net.rehacktive.waspdb.internals.collision.CollisionHash; +import net.rehacktive.waspdb.internals.collision.exceptions.KeyNotFoundException; +import net.rehacktive.waspdb.internals.cryptolayer.CipherManager; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.util.HashMap; +import java.util.List; + +public class WaspHash extends WaspObservable { + + private String path; + private CollisionHash hash; + + protected WaspHash() {} + + protected WaspHash(CipherManager cipherManager, String path) { + super(); + this.hash = new CollisionHash(path, cipherManager); + this.path = path; + } + + /** + * Store a key/value pair + * + * @param key the Object key + * @param value the Object value + */ + public void put(Object key, Object value) { + try { + hash.updateObject(key, value); + notifyObservers(); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + /** + * Retrieve a value associated to the specific key + * @param key the key + * @param the value type + * @return the object, casted automagically! + */ + public T get(Object key) { + try { + return (T) hash.retrieveObject(key); + } + catch(KeyNotFoundException k) { + k.printStackTrace(); + return null; + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Remove the value associated to the specific key + * @param key the key + * @return true if all okay, false if error + */ + public boolean remove(Object key) { + try { + Object obj = hash.removeObject(key); + if(obj!=null) { + notifyObservers(); + return true; + } + return false; + } + catch(KeyNotFoundException k) { + k.printStackTrace(); + return false; + } + catch(Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * Retrieve the list of key for this WaspHash + * @param the key type + * @return a list of keys, casted automagically + */ + public List getAllKeys() { + try { + return hash.getAllKeys(path); + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Retrieve the list of values for this WaspHash + * @param the value type + * @return a list of values, casted automagically + */ + public List getAllValues() { + try { + return hash.getAllValues(path); + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Retrieve the list of key/value for this WaspHash + * @param the key type + * @param the value type + * @return a Java HashMap containing all key/values + */ + public HashMap getAllData() { + try { + return hash.getAllData(path); + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * Flush the current WaspHash - all the key/values will be removed + */ + public void flush() { + try { + File currentDir = new File(path); + for(File f : currentDir.listFiles()) { + if(f.isDirectory()) + FileUtils.deleteDirectory(f); + else + FileUtils.deleteQuietly(f); + } + + notifyObservers(); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + /** + * Return some information about this WaspHash + * @return a string containing the infos + */ + @Override + public String toString() { + return "WaspHash [path=" + path + "] total size: (K) " + FileUtils.sizeOf(new File(path)); + } + + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/WaspListener.java b/waspdb/src/main/java/net/rehacktive/waspdb/WaspListener.java new file mode 100644 index 0000000..39ba36a --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/WaspListener.java @@ -0,0 +1,16 @@ +package net.rehacktive.waspdb; + +import android.util.Log; + +/** + * Created by stefano on 17/03/2015. + */ +public abstract class WaspListener { + + abstract public void onDone(T ret); + + public void onError(String error) { + Log.d("WASPDB", "" + error); + } + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/WaspObservable.java b/waspdb/src/main/java/net/rehacktive/waspdb/WaspObservable.java new file mode 100644 index 0000000..2a811c7 --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/WaspObservable.java @@ -0,0 +1,40 @@ +package net.rehacktive.waspdb; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by stefano on 17/03/2015. + */ +public class WaspObservable { + + List observers; + + public void register(WaspObserver observer) { + if (observers == null) + observers = new ArrayList<>(); + + if (!observers.contains(observer)) + observers.add(observer); + } + + public void unregister(WaspObserver observer) { + if (observers == null) return; + + observers.remove(observer); + } + + public void notifyObservers() { + try { + if (observers == null) return; + + for (WaspObserver observer : observers) { + if (observer != null) observer.onChange(); + + } + } + catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/WaspObserver.java b/waspdb/src/main/java/net/rehacktive/waspdb/WaspObserver.java new file mode 100644 index 0000000..37558ef --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/WaspObserver.java @@ -0,0 +1,9 @@ +package net.rehacktive.waspdb; + +/** + * Created by stefano on 17/03/2015. + */ +public interface WaspObserver { + + void onChange(); +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/CollisionHash.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/CollisionHash.java new file mode 100755 index 0000000..af463d9 --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/CollisionHash.java @@ -0,0 +1,281 @@ +package net.rehacktive.waspdb.internals.collision; + +import android.util.Log; + +import net.rehacktive.waspdb.internals.collision.exceptions.KeyAlreadyExistsException; +import net.rehacktive.waspdb.internals.collision.exceptions.KeyNotFoundException; +import net.rehacktive.waspdb.internals.cryptolayer.CipherManager; +import net.rehacktive.waspdb.internals.utils.Utils; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +public class CollisionHash { + + protected String path; + protected String ext = ".cube"; + + protected int MAXFILESIZE = 65536; + + private CipherManager cipherManager; + + private static String TAG = "COLLISIONHASH"; + + private static String[] cubes = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}; + + // public methods + + public CollisionHash(String path, CipherManager cipherManager) { + this.path = path; + this.cipherManager = cipherManager; + } + + public void storeObject(Object key, Object value) throws Exception { + storeObject(key, value,false); + } + + public void updateObject(Object key, Object value) throws Exception { + storeObject(key,value,true); + } + + public void storeObject(Object key, Object value, boolean update) throws Exception { + try { + String searchKey = getSearchKey(key); // calculate searchKey for file to store + HashMap hash = getHashFromKey(searchKey); // return the hash from the key - it's size is < MAXSIZE-1 + + if(!hash.containsKey(key) || update) { + hash.put(key, value); // add value + storeHashByKey(hash,searchKey); // store hash + } + else { + throw new KeyAlreadyExistsException("key already exists for value "+hash.get(key)); + } + } catch(Exception e) { + throw e; + } + } + + public Object retrieveObject(Object key) throws Exception { + return retrieveObject(key, false); + } + + + public Object removeObject(Object key) throws Exception { + return retrieveObject(key, true); + } + + public HashMap getAllData(String p) throws Exception { + if(p==null) p = path; + HashMap ret = new HashMap(); + + for(String s : cubes) { + String currentPath = p+"/"+s; + if(new File(currentPath).isDirectory()) { + ret.putAll(getAllData(currentPath)); + } + if(new File(currentPath+ext).exists()) { + HashMap data; + data = (HashMap) KryoStoreUtils.readFromDisk(currentPath+ext, HashMap.class, cipherManager); + ret.putAll(data); + } + } + return ret; + } + + public List getAllKeys(String p) throws Exception { + if(p==null) p = path; + List ret = new ArrayList(); + + for(String s : cubes) { + String currentPath = p+"/"+s; + if(new File(currentPath).isDirectory()) { + ret.addAll(getAllKeys(currentPath)); + } + if(new File(currentPath+ext).exists()) { + HashMap data; + data = (HashMap) KryoStoreUtils.readFromDisk(currentPath+ext, HashMap.class,cipherManager); + ret.addAll(data.keySet()); + } + } + return ret; + } + + public List getAllValues(String p) throws Exception { + if(p==null) p = path; + List ret = new ArrayList(); + + for(String s : cubes) { + String currentPath = p+"/"+s; + if(new File(currentPath).isDirectory()) { + ret.addAll(getAllValues(currentPath)); + } + if(new File(currentPath+ext).exists()) { + HashMap data; + data = (HashMap) KryoStoreUtils.readFromDisk(currentPath+ext, HashMap.class,cipherManager); + ret.addAll(data.values()); + } + } + return ret; + } + + // private methods + + private Object retrieveObject(Object key, boolean remove) throws Exception { + Object ret = null; + try { + String searchKey = getSearchKey(key); // calculate searchKey for file to store + HashMap hash = getHashFromKey(searchKey); // return the hash from the key - it's size is < MAXSIZE-1 + ret = hash.get(key); + if(ret!=null) { + Log.d(TAG, System.currentTimeMillis()+": object found with key "+key); + if(remove) { + hash.remove(key); + storeHashByKey(hash,searchKey); // store hash + Log.d(TAG, System.currentTimeMillis()+": object removed with key "+key); + } + } + else { + throw new KeyNotFoundException("key not found for key "+key); + } + } catch(Exception e) { + throw e; + } + return ret; + } + + protected void explodeCube(String file) throws Exception { + Log.d(TAG,"cube full:"+file); + // the cube is full + // get the working directory + String tmpFile = file.substring(0,file.length()-6)+"tmp"+ext; + // original file + File file1 = new File(file); + // tmp file + File file2 = new File(tmpFile); + // Rename file + boolean success = file1.renameTo(file2); + if(success) Log.d(TAG,"created temporary file"); + + String newdirPath = file.substring(0,file.length()-5); + File newdir = new File(newdirPath);; + try { + + // create a directory with tmp name + if(newdir.mkdir()) { + Log.d(TAG,"created new directory:"+newdirPath); + // read content of the file + HashMap hash; + hash = (HashMap) KryoStoreUtils.readFromDisk(tmpFile,HashMap.class,cipherManager); + // and store it's content inside the new directory + for(Object k : hash.keySet()) { + //String key = (String) k; + Object o = hash.get(k); + storeObject(k, o); + } + // remove the tmp file + file2.delete(); + } else { + Log.d(TAG, "can't create "+newdirPath); + throw new Exception(); + } + } + catch(Exception e) { + e.printStackTrace(); + // if something goes wrong during split + // remove the new directory + deleteRecursive(newdir); + // and restore original cube + success = file2.renameTo(file1); + if(success) { + Log.d(TAG,"restored original cube"); + throw new Exception("Unable to add more data - no more space left?"); + } + else throw new Exception("FATAL ON FILESYSTEM DURING ADDING MORE DATA - possible corrupted data!!!"); + } + Log.d(TAG, "explosion done"); + } + + // previously on CollisionStructure + + public String getSearchKey(Object key) throws NoSuchAlgorithmException { + // transform a key to a searchKey for the collision! + final MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + messageDigest.reset(); + messageDigest.update(KryoStoreUtils.serialize(key)); + final byte[] resultByte = messageDigest.digest(); + final String result = Utils.toHexString(resultByte); + String searchKey = result.substring(0,8); + //Log.d("XXX","getSearchKey: "+searchKey+" for key "+key); + return searchKey; + } + + public String getFileFromSearchKey(String searchKey) { + String filePath = ""; + for(int i=searchKey.length();i>0;i--) { + filePath = path; + for(int j=0;j MAXFILESIZE && hash.size() > 1) { + explodeCube(file); + // then recall this method again (recursive) to use the next byte of the key and find the correct file + return getHashFromKey(searchKey); + } + } + // return + return hash; + } + + protected boolean deleteRecursive(File path) throws FileNotFoundException { + if (!path.exists()) throw new FileNotFoundException(path.getAbsolutePath()); + boolean ret = true; + if (path.isDirectory()){ + for (File f : path.listFiles()){ + ret = ret && deleteRecursive(f); + } + } + return ret && path.delete(); + } + + public void storeHashByKey(HashMap hash, String searchKey) throws Exception { + // simply serialize the hash to the file addressed by the key + String file = getFileFromSearchKey(searchKey); + KryoStoreUtils.serializeToDisk(hash, file, cipherManager); + // the file exists, according to the getHashFromKey feature, and it's not full + } + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/KryoStoreUtils.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/KryoStoreUtils.java new file mode 100755 index 0000000..dab58f9 --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/KryoStoreUtils.java @@ -0,0 +1,96 @@ +package net.rehacktive.waspdb.internals.collision; + +import com.esotericsoftware.kryo.Kryo; +import com.esotericsoftware.kryo.io.Input; +import com.esotericsoftware.kryo.io.Output; + +import net.rehacktive.waspdb.internals.cryptolayer.AESSerializer; +import net.rehacktive.waspdb.internals.cryptolayer.CipherManager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; + + +public class KryoStoreUtils { + + private static String TAG = "KRYOSTORE"; + private static Kryo kryoInstance; + + private static Kryo getKryoInstance() { + if(kryoInstance==null) + kryoInstance = new Kryo(); + + return kryoInstance; + } + + // generic i/o + + public static void serializeToDisk(Object obj, String filename, CipherManager cipherManager) throws Exception { + try { + //Long start = System.currentTimeMillis(); + //Log.d(TAG,start+": starting serializeToDisk with password"); + + Output output = new Output(new FileOutputStream(filename)); + if(cipherManager!=null) { + AESSerializer aes = new AESSerializer(getKryoInstance().getSerializer(obj.getClass()), cipherManager); + aes.write(getKryoInstance(), output, obj); + } else { + getKryoInstance().writeObject(output, obj); + } + output.close(); + + //Long end = System.currentTimeMillis(); + //Log.d(TAG,end+": starting serializeToDisk with password"); + //Log.d(TAG,"total time (ms): "+(end-start)); + } + catch(Exception e) { + throw new Exception("\nERROR on serializeToDisk:"+e.getMessage()); + } + } + + public static Object readFromDisk(String filename, Class type, CipherManager cipherManager) throws Exception { + try { + //Long start = System.currentTimeMillis(); + //Log.d(TAG,start+": starting readFromDisk with password"); + + File f = new File(filename); + Object hash; + if(f.exists()) { + Input input = new Input(new FileInputStream(f)); + if(cipherManager!=null) { + AESSerializer aes = new AESSerializer(getKryoInstance().getDefaultSerializer(type), cipherManager); + hash = aes.read(getKryoInstance(), input, type); + } + else { + hash = getKryoInstance().readObject(input, type); + } + input.close(); + + //Long end = System.currentTimeMillis(); + //Log.d(TAG,end+": starting readFromDisk with password"); + //Log.d(TAG,"total time (ms): "+(end-start)); + + return hash; + } + else { + throw new Exception("\nERROR on readFromDisk: can't find "+filename); + } + } + catch(Exception e) { + throw new Exception("\nERROR on readFromDisk:"+e.getMessage()); + } + } + + // serializer for keys + public static byte[] serialize(Object o) { + byte[] ret = new byte[4096]; + Output output = new Output(ret); + getKryoInstance().writeObject(output, o); + return output.toBytes(); + } + +// public static Object cloneObject(Object obj) { +// return getKryoInstance().copy(obj); +// } +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/exceptions/KeyAlreadyExistsException.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/exceptions/KeyAlreadyExistsException.java new file mode 100755 index 0000000..19aa36d --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/exceptions/KeyAlreadyExistsException.java @@ -0,0 +1,9 @@ +package net.rehacktive.waspdb.internals.collision.exceptions; + +public class KeyAlreadyExistsException extends Exception { + + public KeyAlreadyExistsException(String string) { + super(string); + } + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/exceptions/KeyNotFoundException.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/exceptions/KeyNotFoundException.java new file mode 100755 index 0000000..f16bd7e --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/collision/exceptions/KeyNotFoundException.java @@ -0,0 +1,9 @@ +package net.rehacktive.waspdb.internals.collision.exceptions; + +public class KeyNotFoundException extends Exception { + + public KeyNotFoundException(String string) { + super(string); + } + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/cryptolayer/AESSerializer.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/cryptolayer/AESSerializer.java new file mode 100755 index 0000000..608c2d1 --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/cryptolayer/AESSerializer.java @@ -0,0 +1,51 @@ +package net.rehacktive.waspdb.internals.cryptolayer; + +import com.esotericsoftware.kryo.Kryo; +import com.esotericsoftware.kryo.KryoException; +import com.esotericsoftware.kryo.Serializer; +import com.esotericsoftware.kryo.io.Input; +import com.esotericsoftware.kryo.io.Output; + +import java.io.IOException; + +import javax.crypto.Cipher; +import javax.crypto.CipherInputStream; +import javax.crypto.CipherOutputStream; + +public class AESSerializer extends Serializer { + + private final Serializer serializer; + private CipherManager cipherManager; + + public AESSerializer(Serializer serializer, CipherManager cm) { + this.serializer = serializer; + this.cipherManager = cm; + //Security.addProvider(new BouncyCastleProvider()); + } + + public void write(Kryo kryo, Output output, Object object) { + try { + CipherOutputStream cipherStream = new CipherOutputStream(output, cipherManager.getCipher(Cipher.ENCRYPT_MODE)); + + Output cipherOutput = new Output(cipherStream) { + public void close() throws KryoException { + // Don't allow the CipherOutputStream to close the output. + } + }; + kryo.writeObject(cipherOutput, object, serializer); + cipherOutput.flush(); + + cipherStream.close(); + } catch (IOException ex) { + throw new KryoException(ex); + } + + } + + public Object read(Kryo kryo, Input input, Class type) { + CipherInputStream cipherInput = new CipherInputStream(input, cipherManager.getCipher(Cipher.DECRYPT_MODE)); + return kryo.readObject(new Input(cipherInput), type, serializer); + } + + +} \ No newline at end of file diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/cryptolayer/CipherManager.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/cryptolayer/CipherManager.java new file mode 100644 index 0000000..66d78ac --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/cryptolayer/CipherManager.java @@ -0,0 +1,70 @@ +package net.rehacktive.waspdb.internals.cryptolayer; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; + +import javax.crypto.Cipher; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * Created by stefano on 06/08/2014. + */ +public class CipherManager { + + private int ITERATIONS = 10000; + private int KEYSIZE = 256; + + public static String algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"; + + protected Key key; + + protected static CipherManager instance = null; + + private CipherManager() { + // Exists only to defeat instantiation. + } + + public static CipherManager getInstance(char[] p, byte[] s) { + if (instance == null) { + instance = new CipherManager(); + try { + instance.generateSK(p, s); + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + } + return instance; + } + + private void generateSK(char[] passPhrase, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException { + SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(algorithm); + + KeySpec spec = new PBEKeySpec(passPhrase,salt,ITERATIONS, KEYSIZE); + SecretKey secretKey = secretKeyFactory.generateSecret(spec); + + key = new SecretKeySpec(secretKey.getEncoded(), algorithm); + } + + protected Cipher getCipher(int mode) { + try { + Cipher cipher = Cipher.getInstance(algorithm); + cipher.init(mode, key); + + return cipher; + }catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/utils/Salt.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/utils/Salt.java new file mode 100644 index 0000000..474d63c --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/utils/Salt.java @@ -0,0 +1,20 @@ +package net.rehacktive.waspdb.internals.utils; + +/** + * Created by stefano on 20/07/2015. + */ +public class Salt { + + private byte[] salt; + + public Salt() { + } + + public Salt(byte[] salt) { + this.salt = salt; + } + + public byte[] getSalt() { + return salt; + } +} diff --git a/waspdb/src/main/java/net/rehacktive/waspdb/internals/utils/Utils.java b/waspdb/src/main/java/net/rehacktive/waspdb/internals/utils/Utils.java new file mode 100755 index 0000000..1caf460 --- /dev/null +++ b/waspdb/src/main/java/net/rehacktive/waspdb/internals/utils/Utils.java @@ -0,0 +1,77 @@ +package net.rehacktive.waspdb.internals.utils; + +import net.rehacktive.waspdb.internals.cryptolayer.CipherManager; + +import java.io.File; +import java.io.FileNotFoundException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import javax.crypto.SecretKeyFactory; + + +public class Utils { + + public static String md5(String s) throws NoSuchAlgorithmException { + MessageDigest messageDigest; + try { + messageDigest = MessageDigest.getInstance("MD5"); + messageDigest.reset(); + messageDigest.update(s.getBytes()); + byte[] resultByte = messageDigest.digest(); + String result = toHexString(resultByte); + return result; + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + throw e; + } + } + + public static String toHexString(byte[] bytes) { + char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + char[] hexChars = new char[bytes.length * 2]; + int v; + for ( int j = 0; j < bytes.length; j++ ) { + v = bytes[j] & 0xFF; + hexChars[j*2] = hexArray[v/16]; + hexChars[j*2 + 1] = hexArray[v%16]; + } + return new String(hexChars); + } + + public static boolean isEmpty(String s) { + return s==null || s.trim().equals(""); + } + + public static boolean checkForCryptoAvailable() { + try { +// Security.addProvider(new BouncyCastleProvider()); +// for(String s : Security.getAlgorithms("Cipher")) +// System.out.println(s); + SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(CipherManager.algorithm); + return true; + } catch (NoSuchAlgorithmException e) { + return false; + } + } + + public static boolean deleteRecursive(File path) throws FileNotFoundException { + if (!path.exists()) throw new FileNotFoundException(path.getAbsolutePath()); + boolean ret = true; + if (path.isDirectory()){ + for (File f : path.listFiles()){ + ret = ret && deleteRecursive(f); + } + } + return ret && path.delete(); + } + + + public static Salt generateSalt() { + SecureRandom sr = new SecureRandom(); + byte[] output = new byte[256]; + sr.nextBytes(output); + return new Salt(output); + } +} diff --git a/waspdb/src/main/res/values/strings.xml b/waspdb/src/main/res/values/strings.xml new file mode 100644 index 0000000..08ed9dc --- /dev/null +++ b/waspdb/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + WaspDb +