Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Adopt latest changes in libuplink shared file access
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloyan-raev committed Jun 28, 2019
1 parent 634addf commit 1845704
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The backward-incompatible changes compared to the master branch of android-libstorj include:
- Account registration is not suppored anymore. App developers should use the Web API to Storj V3 satellites to register new user accounts and obtain API keys.
- The [Keys](android-libstorj/src/main/java/io/storj/libstorj/Keys.java) class changed from using user, password and mnemonic to using API key and encryption key. This is required to reflect the changed key management in Storj V3.
- The [Keys](android-libstorj/src/main/java/io/storj/libstorj/Keys.java) class changed from using user, password and mnemonic to using API key and encryption access. This is required to reflect the changed key management in Storj V3.
- Error handling is not as fine-grained as in the previous versions that support Storj V2. App developers should not rely on receiving an adequate error code. In most cases the error code will be either [GENERIC_ERROR](https://github.com/storj/android-libstorj/blob/eeeb26c96c4701912d2c3ef08cd1a844cd042a65/android-libstorj/src/main/java/io/storj/libstorj/Storj.java#L66) or [TRANSFER_CANCELED](https://github.com/storj/android-libstorj/blob/eeeb26c96c4701912d2c3ef08cd1a844cd042a65/android-libstorj/src/main/java/io/storj/libstorj/Storj.java#L71).

## Requirements
Expand All @@ -17,7 +17,7 @@ Add the Gradle dependency to the `build.gradle` file of the app module:

```Gradle
dependencies {
implementation 'io.storj:libstorj-android-v3:0.9.1'
implementation 'io.storj:libstorj-android-v3:0.10.0'
}
```

Expand Down
8 changes: 4 additions & 4 deletions android-libstorj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 13
versionName "0.9.1"
versionCode 14
versionName "0.10.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -33,7 +33,7 @@ publish {
userOrg = 'kaloyan-raev'
groupId = 'io.storj'
artifactId = 'libstorj-android-v3'
publishVersion = '0.9.1'
publishVersion = '0.10.0'
desc = 'Libstorj for Android (Storj V3 compatible)'
website = 'https://github.com/storj/android-libstorj'
}
Expand All @@ -42,5 +42,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'io.storj:libuplink-android:0.1.1'
implementation 'io.storj:libuplink-android:0.2'
}
20 changes: 10 additions & 10 deletions android-libstorj/src/main/java/io/storj/libstorj/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@
* <ul>
* <li>Satellite address
* <li>API key
* <li>Encryption key for encrypting and decrypting the transferred files
* <li>Encryption access for encrypting and decrypting the transferred files
* </ul>
*/
public class Keys {

private String apiKey;
private String encryptionKey;
private String encryptionAccess;

/**
* Constructs a new Keys object with the provided credentials.
*
* @param apiKey
* an API key
* @param encryptionKey
* an encryption key
* @param encryptionAccess
* a serialized encryption access
*/
public Keys(String apiKey, String encryptionKey) {
public Keys(String apiKey, String encryptionAccess) {
this.apiKey = apiKey;
this.encryptionKey = encryptionKey;
this.encryptionAccess = encryptionAccess;
}

/**
Expand All @@ -52,11 +52,11 @@ public String getApiKey() {
}

/**
* Returns the encryption key.
* Returns the serialized encryption access.
*
* @return an encryption key
* @return a serialized encryption access
*/
public String getEncryptionKey() {
return encryptionKey;
public String getEncryptionContext() {
return encryptionAccess;
}
}
18 changes: 7 additions & 11 deletions android-libstorj/src/main/java/io/storj/libstorj/Storj.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import io.storj.libuplink.mobile.BucketAccess;
import io.storj.libuplink.mobile.BucketConfig;
import io.storj.libuplink.mobile.BucketInfo;
import io.storj.libuplink.mobile.BucketList;
import io.storj.libuplink.mobile.Config;
import io.storj.libuplink.mobile.EncryptionAccess;
import io.storj.libuplink.mobile.ListOptions;
import io.storj.libuplink.mobile.Mobile;
import io.storj.libuplink.mobile.ObjectInfo;
import io.storj.libuplink.mobile.ObjectList;
import io.storj.libuplink.mobile.Project;
import io.storj.libuplink.mobile.ProjectOptions;
import io.storj.libuplink.mobile.Reader;
import io.storj.libuplink.mobile.ReaderOptions;
import io.storj.libuplink.mobile.Uplink;
Expand Down Expand Up @@ -705,7 +705,7 @@ public Keys getKeys(String passphrase) {
return null;
}

keys = new Keys(props.getProperty("api-key"), props.getProperty("enc-key"));
keys = new Keys(props.getProperty("api-key"), props.getProperty("enc-ctx"));
}
return keys;
}
Expand All @@ -728,7 +728,7 @@ public Keys getKeys(String passphrase) {
public boolean importKeys(Keys keys, String passphrase) {
Properties props = new Properties();
props.setProperty("api-key", keys.getApiKey());
props.setProperty("enc-key", keys.getEncryptionKey());
props.setProperty("enc-ctx", keys.getEncryptionContext());

try {
props.store(new FileWriter(getAuthFile()), null);
Expand Down Expand Up @@ -1715,10 +1715,7 @@ private void runInProject(ProjectRunnable runnable) throws Exception {
Config config = new Config();
Uplink uplink = new Uplink(config, System.getenv("STORJ_TEMP"));
try {
ProjectOptions options = new ProjectOptions();
options.setEncryptionKey(keys.getEncryptionKey().getBytes());

Project project = uplink.openProject(addr, keys.getApiKey(), options);
Project project = uplink.openProject(addr, keys.getApiKey());
try {
runnable.run(project);
} finally {
Expand All @@ -1733,9 +1730,8 @@ private void runInBucket(final String bucketId, final BucketRunnable runnable) t
runInProject(new ProjectRunnable() {
@Override
public void run(Project project) throws Exception {
BucketAccess access = new BucketAccess();
access.setPathEncryptionKey(keys.getEncryptionKey().getBytes());
io.storj.libuplink.mobile.Bucket bucket = project.openBucket(bucketId, access);
EncryptionAccess encryption = Mobile.parseEncryptionAccess(keys.getEncryptionContext());
io.storj.libuplink.mobile.Bucket bucket = project.openBucket(bucketId, encryption);
try {
runnable.run(bucket);
} finally {
Expand Down

0 comments on commit 1845704

Please sign in to comment.