Skip to content

Commit

Permalink
Remove stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
yift-r3 committed Dec 19, 2023
1 parent 6fb2301 commit ec711ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.corda.p2p.linkmanager.state

import net.corda.crypto.client.SessionEncryptionOpsClient
import net.corda.data.p2p.LinkOutMessage
import net.corda.data.p2p.crypto.protocol.AuthenticationProtocolInitiatorDetails
import net.corda.data.p2p.crypto.protocol.AuthenticationProtocolResponderDetails
Expand All @@ -9,7 +10,6 @@ import net.corda.p2p.crypto.protocol.api.AuthenticationProtocolResponder.Compani
import net.corda.p2p.crypto.protocol.api.CheckRevocation
import net.corda.p2p.crypto.protocol.api.SerialisableSessionData
import net.corda.p2p.crypto.protocol.api.Session.Companion.toCorda
import net.corda.p2p.linkmanager.stubs.Encryption
import net.corda.schema.registry.AvroSchemaRegistry
import net.corda.v5.base.exceptions.CordaRuntimeException
import java.nio.ByteBuffer
Expand All @@ -22,11 +22,11 @@ internal data class SessionState(
companion object {
fun AvroSessionData.toCorda(
avroSchemaRegistry: AvroSchemaRegistry,
encryption: Encryption,
encryption: SessionEncryptionOpsClient,
checkRevocation: CheckRevocation,
): SessionState {
val rawData = ByteBuffer.wrap(
encryption.decrypt(this.encryptedSessionData.array()),
encryption.decryptSessionData(this.encryptedSessionData.array()),
)
val sessionData = when (val type = avroSchemaRegistry.getClassType(rawData)) {
AuthenticationProtocolInitiatorDetails::class.java -> {
Expand Down Expand Up @@ -61,11 +61,11 @@ internal data class SessionState(

fun toAvro(
avroSchemaRegistry: AvroSchemaRegistry,
encryption: Encryption,
encryption: SessionEncryptionOpsClient,
): AvroSessionData {
val sessionAvroData = sessionData.toAvro()
val rawData = avroSchemaRegistry.serialize(sessionAvroData)
val encryptedData = encryption.encrypt(rawData.array())
val encryptedData = encryption.encryptSessionData(rawData.array())
return AvroSessionData(
message,
ByteBuffer.wrap(encryptedData),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.corda.p2p.linkmanager.state

import net.corda.crypto.client.SessionEncryptionOpsClient
import net.corda.data.p2p.LinkOutMessage
import net.corda.data.p2p.crypto.ProtocolMode
import net.corda.data.p2p.crypto.protocol.AuthenticatedEncryptionSessionDetails
Expand All @@ -14,7 +15,6 @@ import net.corda.data.p2p.crypto.protocol.Session
import net.corda.p2p.crypto.protocol.api.AuthenticatedSession
import net.corda.p2p.crypto.protocol.api.Session.Companion.toCorda
import net.corda.p2p.linkmanager.state.SessionState.Companion.toCorda
import net.corda.p2p.linkmanager.stubs.Encryption
import net.corda.schema.registry.AvroSchemaRegistry
import net.corda.v5.base.exceptions.CordaRuntimeException
import org.apache.avro.specific.SpecificRecordBase
Expand All @@ -24,6 +24,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
Expand Down Expand Up @@ -55,9 +56,9 @@ YQIDAQAB
private val decrypted = byteArrayOf(1)
private val encrypted = byteArrayOf(2)
private val serialized = ByteBuffer.wrap(decrypted)
private val encryption = mock<Encryption> {
on { decrypt(eq(encrypted)) } doReturn decrypted
on { encrypt(eq(decrypted)) } doReturn encrypted
private val encryption = mock<SessionEncryptionOpsClient> {
on { decryptSessionData(eq(encrypted), anyOrNull()) } doReturn decrypted
on { encryptSessionData(eq(decrypted), anyOrNull()) } doReturn encrypted
}
private val avroSchemaRegistry = mock<AvroSchemaRegistry>()
private val message = mock<LinkOutMessage>()
Expand Down

0 comments on commit ec711ea

Please sign in to comment.