Skip to content

Commit

Permalink
New API for loading LazySodium
Browse files Browse the repository at this point in the history
This is a direct result of #4
  • Loading branch information
gurpreet- committed May 23, 2018
1 parent 398ed21 commit b41d7e8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
ext {
artifactId = "lazysodium-android"
groupId = "com.goterl.lazycode"
version = '1.2.2'
version = '2.0.0'
description = "Lazysodium (Android) makes it effortless for Android " +
"developers to get started with Libsodium's cryptography."
}
Expand Down Expand Up @@ -46,17 +46,28 @@ android {
srcDir "../lazysodium-java/src/main/java"
exclude "com/goterl/lazycode/lazysodium/utils/NativeUtils.java"
exclude "com/goterl/lazycode/lazysodium/SodiumJava.java"
exclude "com/goterl/lazycode/lazysodium/LazySodiumJava.java"
}
}
}

tasks.withType(Javadoc).all { enabled = false }

tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: "com.android.support", module: "support-annotations"
})
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
testImplementation 'junit:junit:4.12'
implementation 'net.java.dev.jna:jna:4.5.1@aar'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Terl Tech Ltd • 23/05/18 13:30 • goterl.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.goterl.lazycode.lazysodium;

import android.support.test.runner.AndroidJUnit4;
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class LoadTest {

@Test
public void loadsCorrectly() {
SodiumAndroid sodiumAndroid = new SodiumAndroid();
TestCase.assertTrue(true);
}

@Test
public void keygen() {
SodiumAndroid sodiumAndroid = new SodiumAndroid();
LazySodiumAndroid lazySodium = new LazySodiumAndroid(sodiumAndroid);

String key = lazySodium.cryptoAuthKeygen();

TestCase.assertNotNull(key);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) Terl Tech Ltd • 23/05/18 16:24 • goterl.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.goterl.lazycode.lazysodium;

import java.nio.charset.Charset;

public class LazySodiumAndroid extends LazySodium {


private final SodiumAndroid sodium;


public LazySodiumAndroid(SodiumAndroid sodium) {
this.sodium = sodium;
}

public LazySodiumAndroid(SodiumAndroid sodium, Charset charset) {
super(charset);
this.sodium = sodium;
}

public SodiumAndroid getSodium() {
return sodium;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public SodiumAndroid() {
*/
public SodiumAndroid(String path) {

// If it's the android platform then we load
// the libsodium.so files from the "src/main/libs" folder.
// Load the libsodium.so files from the "src/main/libs" folder.
// This folder should have folders with ABI names
// such as x86 or x86_64 etc.
Native.register(Sodium.class, path);
Native.register(SodiumAndroid.class, path);

}

Expand Down

0 comments on commit b41d7e8

Please sign in to comment.