Skip to content

Commit

Permalink
Make CredentialSubject abstract (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
iaik-jheher authored Sep 1, 2023
1 parent 1d41c39 commit 4847490
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,15 @@ object TestCredentialScheme : ConstantIndex.CredentialScheme {

@Serializable
@SerialName("TestCredential")
class TestCredential : CredentialSubject {
data class TestCredential (
override val id: String,

@SerialName("name")
val name: String
val name: String,

@SerialName("value")
val value: String

constructor(id: String, name: String, value: String) : super(id = id) {
this.name = name
this.value = value
}

override fun toString(): String {
return "TestCredential(id='$id', name='$name', value='$value')"
}

}
) : CredentialSubject()

class TestCredentialDataProvider(
private val clock: Clock = Clock.System,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,19 @@ import kotlinx.serialization.Serializable
*/
@Serializable
@SerialName("AtomicAttribute2023")
class AtomicAttribute2023 : CredentialSubject {
data class AtomicAttribute2023 (
override val id: String,

@SerialName("name")
val name: String
val name: String,

@SerialName("value")
val value: String
val value: String,

@SerialName("mime-type")
val mimeType: String

constructor(id: String, name: String, value: String, mimeType: String) : super(id = id) {
this.name = name
this.value = value
this.mimeType = mimeType
}
val mimeType: String,
) : CredentialSubject() {

constructor(id: String, name: String, value: String) : this(id, name, value, "application/text")

override fun toString(): String {
return "AtomicAttribute2023(id='$id', name='$name', value='$value', mimeType='$mimeType')"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import kotlinx.serialization.Serializable
* Base class for the subject of a [VerifiableCredential], see subclasses of this class, e.g. [AtomicAttribute2023].
*/
@Serializable
open class CredentialSubject(
abstract class CredentialSubject {
/**
* This is the subjectId of the credential
*/
@SerialName("id")
val id: String,
)
abstract val id: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ import kotlinx.serialization.Serializable
*/
@Serializable
@SerialName(VcDataModelConstants.REVOCATION_LIST_2020)
class RevocationListSubject : CredentialSubject {
data class RevocationListSubject (
override val id: String,

@SerialName("encodedList")
val encodedList: String

constructor(id: String, encodedList: String) : super(id = id) {
this.encodedList = encodedList
}

override fun toString(): String {
return "RevocationListSubject(id='$id', encodedList='$encodedList')"
}

}
val encodedList: String,
) : CredentialSubject()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package at.asitplus.wallet.lib.data

import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

class CredentialSubjectTest : FreeSpec({
"Subclasses are correctly deserialized" {
@Serializable
class SpecializedCredentialTest(override val id: String, @SerialName("not-foo") val foo: String): CredentialSubject()
val result = Json.decodeFromString<SpecializedCredentialTest>("{\"id\":\"Test\",\"not-foo\":\"bar\"}")
result.id shouldBe "Test"
result.foo shouldBe "bar"
}
})

0 comments on commit 4847490

Please sign in to comment.