Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
emeraldsanto committed Mar 1, 2020
2 parents ec553c9 + 1aaa5ef commit 48089cd
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 314 deletions.
6 changes: 6 additions & 0 deletions android/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
8 changes: 7 additions & 1 deletion android/.project
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android_</name>
<name>android</name>
<comment>Project android_ created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
7 changes: 0 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ def safeExtGet(prop, fallback) {
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'maven'

buildscript {
ext.kotlin_version = '1.3.61'
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
Expand All @@ -44,9 +41,6 @@ buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
Expand Down Expand Up @@ -85,7 +79,6 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // From node_modules
implementation "androidx.security:security-crypto:1.0.0-alpha02"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.emeraldsanto.encryptedstorage;

import android.content.SharedPreferences;
import android.content.res.Resources;
import android.util.Log;

import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKeys;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class RNEncryptedStorageModule extends ReactContextBaseJavaModule {

private static String NATIVE_MODULE_NAME = "RNEncryptedStorage";
private static String SHARED_PREFERENCES_FILENAME = "RN_ENCRYPTED_STORAGE_SHARED_PREF";

private SharedPreferences sharedPreferences;

public RNEncryptedStorageModule(ReactApplicationContext context) {
super(context);

try {
this.sharedPreferences = EncryptedSharedPreferences.create(
RNEncryptedStorageModule.SHARED_PREFERENCES_FILENAME,
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
context,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
);
}

catch (Exception ex) {
Log.w(RNEncryptedStorageModule.NATIVE_MODULE_NAME, String.format("Could not initialize SharedPreferences - %s", ex.getLocalizedMessage()));
}
}

@Override
public String getName() {
return RNEncryptedStorageModule.NATIVE_MODULE_NAME;
}

@ReactMethod
public void setItem(String key, String value, Promise promise) {
if (this.sharedPreferences == null) {
promise.reject(new NullPointerException("Could not initialize SharedPreferences"));
return;
}

SharedPreferences.Editor editor = this.sharedPreferences.edit();
editor.putString(key, value);
boolean saved = editor.commit();

if (saved) {
promise.resolve(value);
}

else {
promise.reject(new Exception(String.format("An error occured while saving %s", key)));
}
}

@ReactMethod
public void getItem(String key, Promise promise) {
if (this.sharedPreferences == null) {
promise.reject(new NullPointerException("Could not initialize SharedPreferences"));
return;
}

String value = this.sharedPreferences.getString(key, null);

promise.resolve(value);
}

@ReactMethod
public void removeItem(String key, Promise promise) {
if (this.sharedPreferences == null) {
promise.reject(new NullPointerException("Could not initialize SharedPreferences"));
return;
}

SharedPreferences.Editor editor = this.sharedPreferences.edit();
editor.remove(key);
boolean saved = editor.commit();

if (saved) {
promise.resolve(key);
}

else {
promise.reject(new Exception(String.format("An error occured while removing %s", key)));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.emeraldsanto.encryptedstorage;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.Collections;
import java.util.List;

public class RNEncryptedStoragePackage implements ReactPackage {

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.<NativeModule>singletonList(new RNEncryptedStorageModule(reactContext));
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}

This file was deleted.

8 changes: 0 additions & 8 deletions ios/EncryptedStorage-Bridging-Header.h

This file was deleted.

14 changes: 6 additions & 8 deletions ios/EncryptedStorage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
1CAF8F2F23F383AD00FBCBB2 /* RNEncryptedStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CAF8F2E23F383AD00FBCBB2 /* RNEncryptedStorage.swift */; };
B3E7B58A1CC2AC0600A0062D /* RNEncryptedStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNEncryptedStorage.m */; };
/* End PBXBuildFile section */

Expand All @@ -25,8 +24,7 @@

/* Begin PBXFileReference section */
134814201AA4EA6300B7C361 /* libEncryptedStorage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libEncryptedStorage.a; sourceTree = BUILT_PRODUCTS_DIR; };
1CAF8F2D23F383AC00FBCBB2 /* EncryptedStorage-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "EncryptedStorage-Bridging-Header.h"; sourceTree = "<group>"; };
1CAF8F2E23F383AD00FBCBB2 /* RNEncryptedStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNEncryptedStorage.swift; sourceTree = "<group>"; };
1C15BF842407BE0E004846F8 /* RNEncryptedStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNEncryptedStorage.h; sourceTree = "<group>"; };
B3E7B5891CC2AC0600A0062D /* RNEncryptedStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNEncryptedStorage.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -52,10 +50,9 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
1CAF8F2E23F383AD00FBCBB2 /* RNEncryptedStorage.swift */,
1C15BF842407BE0E004846F8 /* RNEncryptedStorage.h */,
B3E7B5891CC2AC0600A0062D /* RNEncryptedStorage.m */,
134814211AA4EA7D00B7C361 /* Products */,
1CAF8F2D23F383AC00FBCBB2 /* EncryptedStorage-Bridging-Header.h */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -117,7 +114,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1CAF8F2F23F383AD00FBCBB2 /* RNEncryptedStorage.swift in Sources */,
B3E7B58A1CC2AC0600A0062D /* RNEncryptedStorage.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -225,8 +221,9 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../../React/**",
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../../react-native/React/**",
"$(SRCROOT)/../../react-native/Libraries\n$(SRCROOT)/../../react-native/Libraries\n$(SRCROOT)/../../react-native/Libraries/**",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
Expand All @@ -246,8 +243,9 @@
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../../React/**",
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../../react-native/React/**",
"$(SRCROOT)/../../react-native/Libraries\n$(SRCROOT)/../../react-native/Libraries\n$(SRCROOT)/../../react-native/Libraries/**",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
Expand Down
14 changes: 14 additions & 0 deletions ios/RNEncryptedStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// RNEncryptedStorage.h
// EncryptedStorage
//
// Created by Yanick Bélanger on 2020-02-27.
// Copyright © 2020 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>

@interface RNEncryptedStorage : NSObject <RCTBridgeModule>

@end
Loading

0 comments on commit 48089cd

Please sign in to comment.