update for Android Studio 2

This commit is contained in:
Harald Hoyer 2016-07-19 16:48:53 +02:00
parent a76de7534d
commit 983ca61d7b
12 changed files with 268 additions and 78 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View file

@ -3,16 +3,23 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
<option name="gradleJvm" value="1.7" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
</project>

View file

@ -3,7 +3,31 @@
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="masterDetails">
@ -56,5 +80,4 @@
</state>
</states>
</component>
</project>
</project>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

View file

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="SecretShare" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
@ -15,5 +16,4 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
</module>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="SecretShare" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="SecretShare" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
@ -9,10 +9,12 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@ -21,8 +23,9 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
@ -30,43 +33,90 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/24.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/24.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-20.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-24.1.0" level="project" />
<orderEntry type="library" exported="" name="core-3.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
<orderEntry type="library" exported="" name="miglayout-3.7.4" level="project" />
<orderEntry type="library" exported="" name="otto-1.3.5" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-24.1.0" level="project" />
<orderEntry type="library" exported="" name="secretshare-1.4.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-24.1.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-24.1.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-24.1.0" level="project" />
</component>
</module>
</module>

View file

@ -5,7 +5,8 @@ apply plugin: 'maven'
dependencies {
compile 'com.tiemens:secretshare:1.4.1'
compile 'com.google.zxing:core:3.1.0'
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.android.support:appcompat-v7:24.1.0'
compile 'com.squareup:otto:1.3.5'
}
buildscript {
@ -13,7 +14,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.1'
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
@ -24,19 +25,19 @@ allprojects {
}
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "org.surfsite.android.secretshare"
minSdkVersion 15
targetSdkVersion 20
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

View file

@ -15,3 +15,8 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}

View file

@ -17,7 +17,7 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
super(Application.class);
}
public void testEncrypt() throws Exception {
public void testEncryptDescriptionUTF8() throws Exception {
List<SecretShare.ShareInfo> pieces;
int n = 16;
int k = 4;
@ -34,7 +34,7 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
+ "01234567890123456789012345678901234567890123456789";
SecretShare.PublicInfo publicInfo;
SecretShare.PublicInfo pi = null;
List<SecretShare.ShareInfo> si = new ArrayList<SecretShare.ShareInfo>();
List<SecretShare.ShareInfo> si = new ArrayList<>();
final BigInteger secretInteger = Renderer.stringToSecret(cleartext);
final BigInteger modulus;
@ -66,4 +66,54 @@ public class ApplicationTest extends ApplicationTestCase<Application> {
assertEquals(cleartext, Renderer.secretToString(combineOutput.getSecret()));
assertEquals(publicInfo.getDescription(), si.get(0).getPublicInfo().getDescription());
}
public void testEncryptDescriptionEmpty() throws Exception {
List<SecretShare.ShareInfo> pieces;
int n = 16;
int k = 4;
String cleartext
= "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789";
SecretShare.PublicInfo publicInfo;
SecretShare.PublicInfo pi = null;
List<SecretShare.ShareInfo> si = new ArrayList<>();
final BigInteger secretInteger = Renderer.stringToSecret(cleartext);
final BigInteger modulus;
modulus = SecretShare.createAppropriateModulusForSecret(secretInteger);
publicInfo = new SecretShare.PublicInfo(n,
k,
modulus,
null);
final SecretShare.SplitSecretOutput splitSecretOutput = new SecretShare(publicInfo)
.split(secretInteger);
pieces = splitSecretOutput.getShareInfos();
for (int i = 0; i < pieces.size(); i++) {
final SecretShare.ShareInfo piece = pieces.get(i);
final String data = Renderer.encodeShareInfo(piece);
if (pi == null)
pi = Renderer.decodePublicInfo(data);
if (i % 4 == 0)
si.add(Renderer.decodeShareInfo(data, pi));
}
final SecretShare.CombineOutput combineOutput = new SecretShare(pi)
.combine(si);
assertEquals(cleartext, Renderer.secretToString(combineOutput.getSecret()));
assertEquals(publicInfo.getDescription(), si.get(0).getPublicInfo().getDescription());
}
}

View file

@ -36,9 +36,9 @@ public class Renderer {
public static Bitmap createBitmap(String data) {
final Hashtable<EncodeHintType, Object> hints =
new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
BitMatrix result;
new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
BitMatrix result;
final int size = (int) Math.sqrt(data.length() * 8) * 10;
try {
@ -50,8 +50,8 @@ public class Renderer {
hints);
} catch (Exception e) {
e.printStackTrace();
result = null;
}
return null;
}
final int width = result.getWidth();
final int height = result.getHeight();
@ -88,6 +88,9 @@ public class Renderer {
int textWidth = getTextWidth(label, textPaint);
Bitmap codeBitmap = createBitmap(contents);
if (codeBitmap == null)
return null;
final int width = Math.max(textWidth, codeBitmap.getWidth());
Bitmap bmp = Bitmap.createBitmap(width + bitmapMargin * 2,
textHeight + codeBitmap.getHeight() + codePadding * 2 + bitmapMargin * 2,
@ -135,9 +138,9 @@ public class Renderer {
public static ArrayList<String> wrap(String txt, int maxWidth, boolean mustFit, Paint paint) {
int pos = 0;
int start = pos;
ArrayList<String> lines = new ArrayList<String>();
while (true) {
int i = pos;
ArrayList<String> lines = new ArrayList<>();
while (true) {
int i = pos;
if (txt == null) txt = "";
int len = txt.length();
if (pos >= len) {
@ -208,11 +211,14 @@ public class Renderer {
byte[] encBytes = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, encBytes, 0, bytes.length);
encBytes[bytes.length] = (byte) (isUTF8 ? BYTE_IS_UTF8 : BYTE_NOT_UTF8);
return encBytes;
}
encBytes[bytes.length] = isUTF8 ? BYTE_IS_UTF8 : BYTE_NOT_UTF8;
return encBytes;
}
static String tryUnicodeExpand(byte[] in) {
if (in.length == 0)
return null;
byte[] exBytes = new byte[in.length - 1];
System.arraycopy(in, 0, exBytes, 0, in.length - 1);
if (in[in.length - 1] != BYTE_IS_UTF8)
@ -220,11 +226,9 @@ public class Renderer {
final Expand unicodeExpand = new Expand();
try {
return unicodeExpand.expand(exBytes);
} catch (IllegalInputException e) {
e.printStackTrace();
} catch (EndOfInputException e) {
e.printStackTrace();
}
} catch (IllegalInputException | EndOfInputException e) {
e.printStackTrace();
}
return new String(exBytes);
}
@ -240,7 +244,15 @@ public class Renderer {
final SecretShare.PublicInfo publicInfo = piece.getPublicInfo();
final byte[] bytePrimeModulus = publicInfo.getPrimeModulus().toByteArray();
final byte[] byteShare = piece.getShare().toByteArray();
final byte[] byteDescription = tryUnicodeCompress(publicInfo.getDescription());
String description = publicInfo.getDescription();
final byte[] byteDescription;
if ((description != null) && (description.length() > 0)) {
byteDescription = tryUnicodeCompress(description);
} else {
byteDescription = new byte[0];
}
final int byteLen = 4
+ 4 + 4
+ (4 + byteDescription.length)
@ -250,38 +262,58 @@ public class Renderer {
byteBuffer.putInt(piece.getX());
byteBuffer.putInt(publicInfo.getK());
byteBuffer.putInt(publicInfo.getN());
byteBuffer.putInt(byteDescription.length).put(byteDescription);
byteBuffer.putInt(bytePrimeModulus.length).put(bytePrimeModulus);
byteBuffer.putInt(byteShare.length).put(byteShare);
byteBuffer.putInt(byteDescription.length);
if (byteDescription.length > 0)
byteBuffer.put(byteDescription);
byteBuffer.putInt(bytePrimeModulus.length).put(bytePrimeModulus);
byteBuffer.putInt(byteShare.length).put(byteShare);
final String byteEncoded64 = Base64.encodeToString(byteBuffer.array(), Base64.DEFAULT);
return "ssss-android:" + piece.getX() + "/" + publicInfo.getK()
+ ":" + publicInfo.getN() + "=" + byteEncoded64;
}
return "ssssqr:" + piece.getX() + "/" + publicInfo.getK()
+ ":" + publicInfo.getN() + "=" + byteEncoded64;
}
public static SecretShare.PublicInfo decodePublicInfo(final String buf)
throws InvalidParameterException {
if (!buf.startsWith("ssssqr:")) {
throw new InvalidParameterException("Not a SecretShare code.");
}
int index64 = buf.indexOf("=") + 1;
final ByteBuffer byteBuffer;
final byte[] byteDescription;
public static SecretShare.PublicInfo decodePublicInfo(final String buf) {
int index64 = buf.indexOf("=") + 1;
final ByteBuffer byteBuffer;
byteBuffer = ByteBuffer.wrap(Base64.decode(buf.substring(index64), Base64.DEFAULT));
int x = byteBuffer.getInt();
int k = byteBuffer.getInt();
int n = byteBuffer.getInt();
int byteDescriptionLength = byteBuffer.getInt();
final byte[] byteDescription = new byte[byteDescriptionLength];
byteBuffer.get(byteDescription);
if (byteDescriptionLength > 0) {
byteDescription = new byte[byteDescriptionLength];
byteBuffer.get(byteDescription);
} else {
byteDescription = new byte[0];
}
int bytePrimeModulusLength = byteBuffer.getInt();
System.out.printf("len=%d\n", bytePrimeModulusLength);
final byte[] bytePrimeModulus = new byte[bytePrimeModulusLength];
byteBuffer.get(bytePrimeModulus);
BigInteger inPrimeModulus = new BigInteger(bytePrimeModulus);
return new SecretShare.PublicInfo(n, k, inPrimeModulus, tryUnicodeExpand(byteDescription));
}
public static SecretShare.ShareInfo decodeShareInfo(final String buf,
final SecretShare.PublicInfo publicInfo)
throws InvalidParameterException {
if (!buf.startsWith("ssssqr:")) {
throw new InvalidParameterException("Not a SecretShare code.");
}
int index64 = buf.indexOf("=") + 1;
final ByteBuffer byteBuffer;
final byte[] byteDescription;
byteBuffer = ByteBuffer.wrap(Base64.decode(buf.substring(index64), Base64.DEFAULT));
int x = byteBuffer.getInt();
int k = byteBuffer.getInt();
@ -300,11 +332,20 @@ public class Renderer {
}
int byteDescriptionLength = byteBuffer.getInt();
final byte[] byteDescription = new byte[byteDescriptionLength];
byteBuffer.get(byteDescription);
if (publicInfo.getDescription().compareTo(tryUnicodeExpand(byteDescription)) != 0) {
throw new InvalidParameterException("SecretShare.PublicInfo.Description does not match.");
}
if (byteDescriptionLength > 0) {
byteDescription = new byte[byteDescriptionLength];
byteBuffer.get(byteDescription);
} else {
byteDescription = new byte[0];
}
final String description = publicInfo.getDescription();
final String newDescription = tryUnicodeExpand(byteDescription);
if ((description != null && newDescription != null && description.compareTo(newDescription) != 0)
|| (description == null && newDescription != null)
|| (description != null && newDescription == null)) {
throw new InvalidParameterException("SecretShare.PublicInfo.Description does not match.");
}
int bytePrimeModulusLength = byteBuffer.getInt();
final byte[] bytePrimeModulus = new byte[bytePrimeModulusLength];
byteBuffer.get(bytePrimeModulus);

View file

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Tue Jul 19 16:27:54 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip