Skip to content

Commit

Permalink
fix(DIDCommWrapper): Crash when body is empty string (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamada147 authored Jan 17, 2024
1 parent 0dc6039 commit ed537f6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import kotlin.jvm.Throws
* or a more traditional system requiring secure and private identity management, Castor provides the tools and features
* you need to easily create, manage, and resolve DIDs.
*/
class CastorImpl(val apollo: Apollo, private val logger: PrismLogger = PrismLoggerImpl(LogComponent.CASTOR)) : Castor {
class CastorImpl
@JvmOverloads
constructor(
val apollo: Apollo,
private val logger: PrismLogger = PrismLoggerImpl(LogComponent.CASTOR)
) : Castor {
var resolvers: Array<DIDResolver> = arrayOf(
PeerDIDResolver(),
LongFormPrismDIDResolver(this.apollo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ internal class CastorShared {
)
)
)
throw CastorError.InitialStateOfDIDChanged()
throw CastorError.InitialStateOfDIDChanged(e.message)
}

val servicesProperty = DIDDocument.Services(services.toTypedArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ constructor(
*
* @see CastorError
*/
class InitialStateOfDIDChanged : CastorError(
"While trying to resolve Prism DID state changed making it invalid"
class InitialStateOfDIDChanged(message: String? = null) : CastorError(
"While trying to resolve Prism DID state changed making it invalid. $message"
) {
override val code: Int
get() = 26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ interface DIDCommProtocol {
* decentralized system requiring trusted peer-to-peer connections, Mercury provides the tools and features you need to
* establish, manage, and secure your communications easily.
*/
class MercuryImpl(
class MercuryImpl
@JvmOverloads
constructor(
private val castor: Castor,
private val protocol: DIDCommProtocol,
private val api: Api,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ class DIDCommWrapper(castor: Castor, pluto: Pluto, apollo: Apollo) : DIDCommProt
override fun packEncrypted(message: Message): String {
val toString = message.to.toString()

val element = Json.parseToJsonElement(message.body)
val map = jsonObjectToMap(element)
val element: JsonElement = if (message.body.isBlank() || message.body.isEmpty()) {
Json.parseToJsonElement("{}")
} else {
Json.parseToJsonElement(message.body)
}
val map: Map<String, Any?> = jsonObjectToMap(element)

val didCommMsg = org.didcommx.didcomm.message.Message(
id = message.id,
Expand Down

0 comments on commit ed537f6

Please sign in to comment.