Skip to content

Commit

Permalink
Added java- and kotlin-specific EThreeParams. Added forgotten @jvmove…
Browse files Browse the repository at this point in the history
  • Loading branch information
BuddahLD committed Feb 14, 2020
1 parent 8b8e292 commit d46616a
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import com.virgilsecurity.android.common.exception.*
import com.virgilsecurity.android.common.manager.GroupManager
import com.virgilsecurity.android.common.manager.LookupManager
import com.virgilsecurity.android.common.manager.TempChannelManager
import com.virgilsecurity.android.common.model.*
import com.virgilsecurity.android.common.model.DerivedPasswords
import com.virgilsecurity.android.common.model.FindUsersResult
import com.virgilsecurity.android.common.model.Group
import com.virgilsecurity.android.common.model.LookupResult
import com.virgilsecurity.android.common.model.ratchet.RatchetChannel
import com.virgilsecurity.android.common.model.temporary.TemporaryChannel
import com.virgilsecurity.android.common.storage.cloud.CloudKeyManager
Expand Down Expand Up @@ -124,14 +127,6 @@ abstract class EThreeCore {
val cardManager: CardManager
val identity: String

protected constructor(params: EThreeParams) : this(params.identity,
params.tokenCallback,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval,
params.context)

protected constructor(identity: String,
getTokenCallback: OnGetTokenCallback,
keyChangedCallback: OnKeyChangedCallback?,
Expand Down Expand Up @@ -325,9 +320,9 @@ abstract class EThreeCore {
* @throws FindUsersException(FindUsersException.Description.CARD_WAS_NOT_FOUND) If card
* duplicates was found or at least one card was not found.
*/
fun findUsers(identities: List<String>,
forceReload: Boolean = false,
checkResult: Boolean = true): Result<FindUsersResult> =
@JvmOverloads fun findUsers(identities: List<String>,
forceReload: Boolean = false,
checkResult: Boolean = true): Result<FindUsersResult> =
searchWorker.findUsers(identities, forceReload, checkResult)

/**
Expand All @@ -343,7 +338,7 @@ abstract class EThreeCore {
* @throws FindUsersException(FindUsersException.Description.CARD_WAS_NOT_FOUND) If card
* duplicates was found or at least one card was not found.
*/
fun findUser(identity: String, forceReload: Boolean = false): Result<Card> =
@JvmOverloads fun findUser(identity: String, forceReload: Boolean = false): Result<Card> =
searchWorker.findUser(identity, forceReload)

/**
Expand Down Expand Up @@ -486,7 +481,7 @@ abstract class EThreeCore {
* @throws GroupException.Description.INVALID_PARTICIPANTS_COUNT If participants count is out
* of [Group.VALID_PARTICIPANTS_COUNT_RANGE] range.
*/
fun createGroup(identifier: Data, users: FindUsersResult? = null): Result<Group> =
@JvmOverloads fun createGroup(identifier: Data, users: FindUsersResult? = null): Result<Group> =
groupWorker.createGroup(identifier, users)

/**
Expand Down Expand Up @@ -532,6 +527,7 @@ abstract class EThreeCore {
*
* @return New [Group].
*/
@JvmOverloads
fun createGroup(identifier: String, users: FindUsersResult? = null): Result<Group> =
groupWorker.createGroup(identifier, users)

Expand Down Expand Up @@ -976,6 +972,7 @@ abstract class EThreeCore {
* @throws EThreeException(EThreeException.Description.VERIFICATION_FAILED)
* @throws rethrows [VirgilCrypto.authDecrypt]
*/
@JvmOverloads
fun authDecrypt(inputStream: InputStream, outputStream: OutputStream, user: Card? = null) =
streamsEncryptWorker.authDecrypt(inputStream, outputStream, user)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class EThreeParams(
val identity: String,

// Callback to get Virgil access token.
val tokenCallback: OnGetTokenCallback,
// This method should return valid Json Web Token [String] representation with identity
// (in it) of the user which will use this class.
val tokenCallback: () -> String,

// Context
val context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Group internal constructor(
*
* @return decrypted byte array.
*/
fun decrypt(data: ByteArray, senderCard: Card, date: Date? = null): ByteArray {
@JvmOverloads fun decrypt(data: ByteArray, senderCard: Card, date: Date? = null): ByteArray {
require(data.isNotEmpty()) { "\'data\' should not be empty" }

val encrypted = GroupSessionMessage.deserialize(data)
Expand Down Expand Up @@ -216,7 +216,7 @@ class Group internal constructor(
*
* @return decrypted String.
*/
fun decrypt(text: String, senderCard: Card, date: Date? = null): String {
@JvmOverloads fun decrypt(text: String, senderCard: Card, date: Date? = null): String {
require(text.isNotEmpty()) { "\'text\' should not be empty" }

val data: Data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* (3) Neither the name of virgil nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.virgilsecurity.android.common.model.java

import android.content.Context
import com.virgilsecurity.android.common.callback.OnGetTokenCallback
import com.virgilsecurity.android.common.callback.OnKeyChangedCallback
import com.virgilsecurity.android.common.util.Defaults
import com.virgilsecurity.sdk.client.CardClient
import com.virgilsecurity.sdk.common.TimeSpan
import com.virgilsecurity.sdk.crypto.KeyPairType

/**
* EThreeParams
*/
class EThreeParams(
// Identity of user.
val identity: String,

// Callback to get Virgil access token.
val tokenCallback: OnGetTokenCallback,

// Context
val context: Context) {

// Callback to notify the change of User's keys.
var keyChangedCallback: OnKeyChangedCallback? = null

// Enables ratchet operations.
var enableRatchet: Boolean = Defaults.enableRatchet

// TimeSpan of automatic rotate keys for double ratchet.
var keyRotationInterval: TimeSpan = Defaults.keyRotationInterval

// Default key pair type
var keyPairType: KeyPairType = Defaults.keyPairType
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ import android.content.Context
import com.virgilsecurity.android.common.EThreeCore
import com.virgilsecurity.android.common.callback.OnGetTokenCallback
import com.virgilsecurity.android.common.callback.OnKeyChangedCallback
import com.virgilsecurity.android.common.model.DerivedPasswords
import com.virgilsecurity.android.common.util.Const.NO_CONTEXT
import com.virgilsecurity.android.common.util.Defaults
import com.virgilsecurity.android.ethreeenclave.interaction.model.EThreeParamsEnclave
import com.virgilsecurity.common.model.Result
import com.virgilsecurity.sdk.androidutils.storage.AndroidKeyEntry
import com.virgilsecurity.sdk.androidutils.storage.AndroidKeyStorage
Expand Down Expand Up @@ -115,16 +113,29 @@ class EThree
initializeCore()
}

constructor(params: EThreeParamsEnclave) : this(params.identity,
params.tokenCallback,
params.context,
params.alias,
params.isAuthenticationRequired,
params.keyValidityDuration,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval)
constructor(params: com.virgilsecurity.android.ethreeenclave.interaction.model.EThreeParams) : this(
params.identity,
params.tokenCallback,
params.context,
params.alias,
params.isAuthenticationRequired,
params.keyValidityDuration,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval)

constructor(params: com.virgilsecurity.android.ethreeenclave.interaction.model.java.EThreeParams) : this(
params.identity,
params.tokenCallback,
params.context,
params.alias,
params.isAuthenticationRequired,
params.keyValidityDuration,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval)

@JvmOverloads constructor(
identity: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* (3) Neither the name of virgil nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.virgilsecurity.android.ethreeenclave.interaction.model

import android.content.Context
import com.virgilsecurity.android.common.callback.OnGetTokenCallback
import com.virgilsecurity.android.common.callback.OnKeyChangedCallback
import com.virgilsecurity.android.common.util.Defaults
import com.virgilsecurity.sdk.common.TimeSpan
import com.virgilsecurity.sdk.crypto.KeyPairType

/**
* EThreeParamsEnclave
*/
data class EThreeParams(
// Identity of user.
val identity: String,

// Callback to get Virgil access token.
// This method should return valid Json Web Token [String] representation with identity
// (in it) of the user which will use this class.
val tokenCallback: () -> String,

// Context
val context: Context) {

// Alias for Android Key Storage
var alias: String = "VirgilAndroidKeyStorage"

// Whether authentication is required
var isAuthenticationRequired: Boolean = true

// Key validity duration
var keyValidityDuration: Int = 60 * 5

// Callback to notify the change of User's keys.
var keyChangedCallback: OnKeyChangedCallback? = null

// Enables ratchet operations.
var enableRatchet: Boolean = Defaults.enableRatchet

// TimeSpan of automatic rotate keys for double ratchet.
var keyRotationInterval: TimeSpan = Defaults.keyRotationInterval

// Default key pair type
var keyPairType: KeyPairType = Defaults.keyPairType
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.virgilsecurity.android.ethreeenclave.interaction.model
package com.virgilsecurity.android.ethreeenclave.interaction.model.java

import android.content.Context
import com.virgilsecurity.android.common.callback.OnGetTokenCallback
Expand All @@ -43,7 +43,7 @@ import com.virgilsecurity.sdk.crypto.KeyPairType
/**
* EThreeParamsEnclave
*/
data class EThreeParamsEnclave(
data class EThreeParams(
// Identity of user.
val identity: String,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import android.content.Context
import com.virgilsecurity.android.common.EThreeCore
import com.virgilsecurity.android.common.callback.OnGetTokenCallback
import com.virgilsecurity.android.common.callback.OnKeyChangedCallback
import com.virgilsecurity.android.common.model.EThreeParams
import com.virgilsecurity.android.common.util.Const.NO_CONTEXT
import com.virgilsecurity.android.common.util.Defaults
import com.virgilsecurity.common.model.Result
Expand Down Expand Up @@ -77,13 +76,23 @@ class EThree
initializeCore()
}

constructor(params: EThreeParams) : this(params.identity,
params.tokenCallback,
params.context,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval)
constructor(params: com.virgilsecurity.android.common.model.EThreeParams) : this(
params.identity,
params.tokenCallback,
params.context,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval)

constructor(params: com.virgilsecurity.android.common.model.java.EThreeParams) : this(
params.identity,
params.tokenCallback,
params.context,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval)

@JvmOverloads constructor(
identity: String,
Expand Down

0 comments on commit d46616a

Please sign in to comment.